P
Patti
Sorry to be a pain...still working on building my loop. Column A contains
names, including the some of the same names consecutively. I would expect
that if name in A is the same for the first three rows, the Case statements
would execute, provided that the cells in column B are not null, but when I
get to a new name in the 4th row, I should get the message box saying "moved
on!"
As it is, it just keeps going though the entire list even though the name
(agtname) changes.
I also tried to wrap the "If Cells(i, 2).Value <> "" Then" and Case
statement in something like "Do while agtname = agtname" but it hangs up.
In a nutshell, I need to know how to set my agtname variable as the
value/text in "i" of column A, and keep it until I run across a new name,
which then becomes agtname. Also, how do i capture the row address I was on
when I agtname changed so that I can use it later? For example, say agtname
becomes Patti on row 5, and stays Patti until in turns to Bob on row 7. I
want to hold a variable for Patti called something like "firstfound" with an
address of A5. When I get to Bob, "firstfound" will become A7.
I hope that's clear!
TIA
Option Explicit
Private Sub testloop()
Dim lstrow As Long
Dim i As Long
Dim j As Long
Dim agtname As String
lstrow = Range("a" & Rows.Count).End(xlUp).Row
For i = 2 To lstrow
agtname = Range("a" & i).Text
If agtname = agtname Then
If Cells(i, 2).Value <> "" Then
Select Case Cells(i, 2)
Case "This"
MsgBox "Current Type for " & agtname & " is blah blah blah
" & i
Case "That"
MsgBox "Current Type for " & agtname & " is yada yada yada
" & i
Case Else
MsgBox "Current Type for " & agtname & " is " & Cells(i, 2)
& " " & i
End Select
End If
Else
MsgBox "moved on!"
End If
Next i
End Sub
names, including the some of the same names consecutively. I would expect
that if name in A is the same for the first three rows, the Case statements
would execute, provided that the cells in column B are not null, but when I
get to a new name in the 4th row, I should get the message box saying "moved
on!"
As it is, it just keeps going though the entire list even though the name
(agtname) changes.
I also tried to wrap the "If Cells(i, 2).Value <> "" Then" and Case
statement in something like "Do while agtname = agtname" but it hangs up.
In a nutshell, I need to know how to set my agtname variable as the
value/text in "i" of column A, and keep it until I run across a new name,
which then becomes agtname. Also, how do i capture the row address I was on
when I agtname changed so that I can use it later? For example, say agtname
becomes Patti on row 5, and stays Patti until in turns to Bob on row 7. I
want to hold a variable for Patti called something like "firstfound" with an
address of A5. When I get to Bob, "firstfound" will become A7.
I hope that's clear!
TIA
Option Explicit
Private Sub testloop()
Dim lstrow As Long
Dim i As Long
Dim j As Long
Dim agtname As String
lstrow = Range("a" & Rows.Count).End(xlUp).Row
For i = 2 To lstrow
agtname = Range("a" & i).Text
If agtname = agtname Then
If Cells(i, 2).Value <> "" Then
Select Case Cells(i, 2)
Case "This"
MsgBox "Current Type for " & agtname & " is blah blah blah
" & i
Case "That"
MsgBox "Current Type for " & agtname & " is yada yada yada
" & i
Case Else
MsgBox "Current Type for " & agtname & " is " & Cells(i, 2)
& " " & i
End Select
End If
Else
MsgBox "moved on!"
End If
Next i
End Sub