This code moves down column A to the end of the list:
Sub Test3()
Dim x As String
Dim found As Boolean
' Select first line of data.
Range("A2").Select
' Set search variable value.
x = "test"
' Set Boolean variable "found" to false.
found = False
' Set Do loop to stop at empty cell.
Do Until IsEmpty(ActiveCell)
' Check active cell for search value.
If ActiveCell.Value = x Then
found = TRUE
Exit Do
End If
' Step down 1 row from present location.
ActiveCell.Offset(1, 0).Select
Loop
' Check for found.
If found = True Then
Msgbox "Value found in cell " & ActiveCell.Address
Else
Msgbox "Value not found"
End If
End Sub
No comments:
Post a Comment