Guraknugen
New Member
- Joined
- Mar 15, 2017
- Messages
- 36
Test code:
Type the following in the following cells:
Expected result (?) in the monitor window:
Result in the monitor window:
Why is the first line in the monitor 2 instead of 1, and what can I do about it?
Code:
Option Explicit
Sub SearchTest()
Dim Search As Range
Dim MyRange As Range
Set MyRange = Worksheets(1).Range("A1:A8")
Set Search = MyRange.Find(What:="0", LookIn:=xlValues)
Debug.Print Search.Row
Set Search = MyRange.Find(What:="00", LookIn:=xlValues)
Debug.Print Search.Row
Set Search = MyRange.Find(What:="000", LookIn:=xlValues)
Debug.Print Search.Row
Set Search = MyRange.Find(What:="0000", LookIn:=xlValues)
Debug.Print Search.Row
Set Search = MyRange.Find(What:="1", LookIn:=xlValues)
Debug.Print Search.Row
Set Search = MyRange.Find(What:="11", LookIn:=xlValues)
Debug.Print Search.Row
Set Search = MyRange.Find(What:="111", LookIn:=xlValues)
Debug.Print Search.Row
Set Search = MyRange.Find(What:="1111", LookIn:=xlValues)
Debug.Print Search.Row
End Sub
Code:
A1: '0
A2: '00
A3: '000
A4: '0000
A5: '1
A6: '11
A7: '111
A8: '1111
Code:
1
2
3
4
5
6
7
8
Code:
2
2
3
4
5
6
7
8
Why is the first line in the monitor 2 instead of 1, and what can I do about it?