Dim valCheck As Variant
For i = 0 To row1
For j = 0 To col1
MsgBox ("started" & i)
valCheck = Range("A1").Offset(i, j).Value
MsgBox (valCheck)
If valCheck = "Details" Then
MsgBox ("found")
ActiveCell = Range("A1").Offset(i + 1, j)
Exit For
Exit For
End If
Next j
Next i
2 Answers
You don't need to have 2 For loops and Exit For, you can simply use the Find function instead.
Dim FindRng As Range
Set FindRng = Cells.Find("Details")
If Not FindRng Is Nothing Then ' Find was successful
FindRng.Select ' <-- not sure what you want to do after you find the cell with "Details" ?
Else ' Find failed
MsgBox "Unable to find 'details'", vbCritical
End If
Comments
As soon as the first Exit For executes, it bypasses the second. You need to place the second Exit For outside the inner loop.
Dim valCheck As Variant
For i = 0 To row1
For j = 0 To col1
MsgBox ("started" & i)
valCheck = Range("A1").Offset(i, j).Value
MsgBox (valCheck)
If valCheck = "Details" Then
MsgBox ("found")
ActiveCell = Range("A1").Offset(i + 1, j)
Exit For
End If
Next j
If valCheck = "Details" Then Exit For
Next i
Exit Forlike this, it will only use the first one, and exit theFor jloop. what are you trying to achieve ?