Deimos
New Member
- Joined
- Jun 4, 2011
- Messages
- 2
Hi,
I'm a first time poster. I'm creating a sub to search a range and locate a cell that contains the same first two letters of a string. Once located I want to show the cell address in a message box. The below code gives the Run time error '91': Object variable or with block variable not set. The line that receives the error is in bold below. I'm unsure where i've gone wrong, could someone please assist me.
I'm a first time poster. I'm creating a sub to search a range and locate a cell that contains the same first two letters of a string. Once located I want to show the cell address in a message box. The below code gives the Run time error '91': Object variable or with block variable not set. The line that receives the error is in bold below. I'm unsure where i've gone wrong, could someone please assist me.
Rich (BB code):
Sub testmatch()
Dim extractedtext As String
Dim r As Integer
Dim c As Integer
Dim region As Range
r = 2
c = 2
Do
extractedtext = Sheet2.Cells(r, c).Value
region = Application.Match(extractedtext & "*", Sheet1.Range("C4:R27"), 0)
If Not region Is Nothing Then
MsgBox extractedtext & "Found at" & region
End If
r = r + 1
Loop Until Sheet2.Cells(r, c).Value = ""
End Sub