G
Guest
Excel 2003
I am trying to use a macro to search column a for the Text "RD". I have
used the code below many times to find each instance in a column. Now, I
want to find each instance, but after one instance, assign the value to a
variable, go to the next instance, assign that to a variable, and then
perform some operations. on that range. I'm only concerned at this point
with getting the selection and variable assignments to work. The code below
works for the first instance, but always assigns 5 to J. I am stumped.
Thanks in advance for any help.
Sub SelectRDRows()
Dim I As Long
Dim J As Long
Dim BegCell As Long
Dim EndCell As Long
For I = Range("A65536").End(xlUp).Row To 1 Step -1
If Range("A" & I).Value = "RD" Then
EndCell = I - 1
For J = Range("A" & EndCell).End(xlUp).Row To 1 Step -1
If Range("A" & J).Value = "RD" Then
BegCell = J + 1
Range("A" & BegCell & ":" & "A" & EndCell).Select
Exit For
End If
Next J
End If
Next I
End Sub
I am trying to use a macro to search column a for the Text "RD". I have
used the code below many times to find each instance in a column. Now, I
want to find each instance, but after one instance, assign the value to a
variable, go to the next instance, assign that to a variable, and then
perform some operations. on that range. I'm only concerned at this point
with getting the selection and variable assignments to work. The code below
works for the first instance, but always assigns 5 to J. I am stumped.
Thanks in advance for any help.
Sub SelectRDRows()
Dim I As Long
Dim J As Long
Dim BegCell As Long
Dim EndCell As Long
For I = Range("A65536").End(xlUp).Row To 1 Step -1
If Range("A" & I).Value = "RD" Then
EndCell = I - 1
For J = Range("A" & EndCell).End(xlUp).Row To 1 Step -1
If Range("A" & J).Value = "RD" Then
BegCell = J + 1
Range("A" & BegCell & ":" & "A" & EndCell).Select
Exit For
End If
Next J
End If
Next I
End Sub