Help with an error in my code pls

seriouslystuck

Board Regular
Joined
Sep 24, 2009
Messages
97
Hi

Can someone please help me! Im getting the error object variable or with block variable not set, at the red txt

Dim searchdate As String Dim c As Range Dim firstaddress As String Dim blnRepeat As Boolean

blnRepeat = True

Do While blnRepeat = True

searchdate = Range("FH5").Value

With Range("F:F") Set c = .Find(searchdate, LookIn:=xlValues) If Not c Is Nothing Then firstaddress = c.Address blnFndMtch = True Do c.Offset(0, 0).Value = Range("FI5").Value blnRepeat = False Set c = .FindNext(c) Loop While Not c Is Nothing And c.Address <> firstaddress End If End With

If c Is Nothing Then

Exit Do

End If

Loop

End Sub
 

Excel Facts

Wildcard in VLOOKUP
Use =VLOOKUP("Apple*" to find apple, Apple, or applesauce
It didn't format particularly well there, hard to make up where all the loops / ifs begin and end?

Adam
 
Upvote 0
Sorry code didnt paste properly

Dim searchdate As String Dim c As Range Dim firstaddress As String Dim blnRepeat As Boolean

blnRepeat = True

Do While blnRepeat = True

searchdate = Range("FH5").Value

With Range("F:F")
Set c = .Find(searchdate, LookIn:=xlValues)
If Not c Is Nothing Then
firstaddress = c.Address blnFndMtch = True
Do
c.Offset(0, 0).Value = Range("FI5").Value
blnRepeat = False
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstaddress 'this is the error line
End If
End With

If c Is Nothing Then

Exit Do

End If

Loop

End Sub
 
Upvote 0
Try

Code:
Sub test()
Dim searchdate As String
Dim c As Range
Dim firstaddress As String
Dim blnRepeat As Boolean
blnRepeat = True
Do While blnRepeat = True
    searchdate = Range("FH5").Value
    With Range("F:F")
        Set c = .Find(searchdate, LookIn:=xlValues)
        If Not c Is Nothing Then
            firstaddress = c.Address
            blnFndMtch = True
            Do
                c.Offset(0, 0).Value = Range("FI5").Value
                blnRepeat = False
                Set c = .FindNext(c)
            Loop While Not c Is Nothing And c.Address <> firstaddress
        End If
    End With
    If c Is Nothing Then
    Exit Do
    End If
Loop
End Sub
 
Upvote 0
try this

Dim searchdate As String
Dim c As Range
Dim firstaddress As String
Dim blnRepeat As Boolean

blnRepeat = True

Do While blnRepeat = True

searchdate = Range("FH5").Value

With Range("F:F")
Set c = .Find(searchdate, LookIn:=xlValues)
If Not c Is Nothing Then
firstaddress = c.Address
blnFndMtch = True
Do
c.Offset(0, 0).Value = Range("FI5").Value
blnRepeat = False
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstaddress 'this is the error line
End If
End With

If c Is Nothing Then

Exit Do

End If

Loop

End Sub
 
Upvote 0

Forum statistics

Threads
1,224,592
Messages
6,179,789
Members
452,942
Latest member
VijayNewtoExcel

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top