I'm having a go at using VBA for excel, having used it a bit in Access.
What I'm trying to do in this exercise is have the code scan column C, and if the cell is empty it needs to remember the value in column A, and then clear cells B & C for all instances of value A
example (small sample)
The end result shoud something like:
Essentially what I'm trying to do is something like:
and I've come up with the following code which has limited success.
I think it needs to run again in the opposite direction but i'm unsure how to do it.
Does anyone have any suggestions or perhaps can think of a better way to achieve the result?
What I'm trying to do in this exercise is have the code scan column C, and if the cell is empty it needs to remember the value in column A, and then clear cells B & C for all instances of value A
example (small sample)
Code:
-- ---- A ---- --B ---- C
1 ---- 210 ---- 20 ---- 40
2 ---- 210 ---- 20 ----
3 ---- 210 ---- 30 ----
4 ---- 230 ---- 20 ---- 40
5 ---- 230 ---- 32 ---- 40
6 ---- 230 ---- 20 ---- 40
7 ---- 250 ---- 21 ----
8 ---- 250 ---- 23 ----
9 ---- 250 ---- 54 ---- 40
Code:
---- ---A ---- --B ---- C
1 ---- 210
2 ---- 210
3 ---- 210
4 ---- 230 ---- 20 ---- 40
5 ---- 230 ---- 32 ---- 40
6 ---- 230 ---- 20 ---- 40
7 ---- 250
8 ---- 250
9 ---- 250
Code:
If C = null Then
For each where A = A
B & C = null
Next
Code:
Sub CheckSheet()
Dim intRow
Dim intLastRow
Dim TargetVar
intLastRow = Range("C65536").End(xlUp).Row
For intRow = intLastRow To 1 Step -1
Rows(intRow).Select
If Cells(intRow, 3).Value = "" Then
Cells(intRow, 3).Select
TargetVar = Cells(intRow, 1).Value
End If
If Cells(intRow, 1).Value = TargetVar Then
Cells(intRow, 2).Value = ""
Cells(intRow, 3).Value = ""
End If
Next intRow
Range("c1").Select
End Sub
Does anyone have any suggestions or perhaps can think of a better way to achieve the result?