I am new to writing VBA code and have come across this code below online which is very similar to what I am trying to do. However when I try to run it, it highlights the line Loop While Not c Is Nothing And c.Address <> firstAddress and a message pops up saying "Object variable or With block variable not set".
Does anyone know how to fix this? Any help is much appreciated!
Sub Commodity()
'
' Commodity Macro
' Commodity
'
'
With Worksheets(1).Range("a1:a500")
Set c = .Find(2, LookIn:=xlValues)
If Not c Is Nothing Then
firstAddress = c.Address
Do
c.Value = 5
Set c = .FindNext(c)
Loop While Not c Is Nothing And c.Address <> firstAddress
End If
End With
End Sub