I want to look for the word "double" in column N from the first row to the last available row (The total number of rows is extracted from cell E1).
If the word "double" is found, Message box "error" would appear.
Can anyone help me? Thanks
I want to look for the word "double" in column N from the first row to the last available row (The total number of rows is extracted from cell E1).
If the word "double" is found, Message box "error" would appear.
Can anyone help me? Thanks
Welcome to StackOverflow. Next time, please include what you have tried in your question.
This does what you are asking:
Sub findDouble()
' get row number of last row to check
Dim NumberOfCells As Integer
NumberOfCells = ActiveSheet.Range("E1").Value
' loop through all cells in column N
For Each cell In ActiveSheet.Range("N1:N" & NumberOfCells)
' throw error message if cell value equals double
If cell.Value = "double" Then MsgBox "error"
Next cell
End
I'm assuming here that you want to run this on the currenty active worksheet. A more water-proof way is of course to specify the sheet by its name or number.
You probably want to refine the code though, e.g. to include the cell address the 'double' was found in in your error message, like so:
MsgBox "error in cell " & cell.Address