Hi,
I found some code here, https://support.microsoft.com/en-us/kb/299036, that shows how to loop through a range of cells until a value is found. However the code exits and continues to say "value not found". I am new to VBA and looking to go through column A until any value is found.
I modified the If statement to If Not isempty(activecell.value) so that if it finds a cell with data it will set the variable as True. It should then exit the loop and go to the next If statement and since found = true list that the value is found. Eventually once the value is found I will set the IF found = True then ActiveCell.Copy Destination:=Range("A17"). However I can't get the first Do While statement to actually exit with found = true.
Is this happening because it is stopping on the first loop because IsEmpty(activecell) is being used? In the loop we do move down to the next row in the column.
Sub enterName() Dim x As String Dim found As Boolean ' Select first line of data. Range("A17").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 Not IsEmpty(ActiveCell.Value) 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