TheRedCardinal
Active Member
- Joined
- Jul 11, 2019
- Messages
- 252
- Office Version
- 365
- 2021
- Platform
- Windows
Hi all,
I have a simple Sub that replaces one value in a cell with another from a lookup table. It loops around the length of the column replacing row by row
I get an "Object Variable or With Block variable not set" error highlighting the line between With WS1 and End With.
CountryCol Variable is clearly declared within the Sub; WS1 is declared as a worksheet in the Public section of the module.
The text it is looking for is definitely there too.
I have missed something obvious - so can anybody spot it?
Thanks!
I have a simple Sub that replaces one value in a cell with another from a lookup table. It loops around the length of the column replacing row by row
Code:
Sub UpdateCountry()
Dim lr As Long, i As Long
Dim CountryCol As Range
Dim x As Variant
Set ws1 = Sheets("2. Final Data")
ws1.Select
lr = Range("A1").End(xlDown).Row
With ws1
CountryCol = .Range("A1:Z1").Find("Country/region")
End With
For i = 1 To lr
x = Application.VLookup(Cells(i, CountryCol), Sheets("Data Sheet").Columns("A:B"), 2, False)
If Not (IsError(x)) Then
Cells(i, CountryCol).Value = x
End If
Next i
End Sub
I get an "Object Variable or With Block variable not set" error highlighting the line between With WS1 and End With.
CountryCol Variable is clearly declared within the Sub; WS1 is declared as a worksheet in the Public section of the module.
The text it is looking for is definitely there too.
I have missed something obvious - so can anybody spot it?
Thanks!