iaindowner
New Member
- Joined
- Aug 12, 2014
- Messages
- 18
I have some code which loops through a range of cells. In each cell I want to insert a VLOOKUP formula which will look up a value relative to the active cell in another sheet. Currently I am getting an error "object variable or With Block variable not set".
I am relatively inexperienced in VBA but have been racking my brains for hours. In the code below 'k' is a list box vaule.
I think that the issue may partly be down to the fact that the vlookup formula is using the cell value rather than the cell address.
I am relatively inexperienced in VBA but have been racking my brains for hours. In the code below 'k' is a list box vaule.
I think that the issue may partly be down to the fact that the vlookup formula is using the cell value rather than the cell address.
Code:
Sub Retrieve_Click()Dim k As Integer
k = List.Value
Dim off As Range
Set off = Range("D3", Range("D3").End(xlDown)).Offset(0, k * 2)
off.Select
For Each Cell In off.Cells
k = List.Value
Dim ff As Range
ff = Sheets(k).Range("B6:E100")
Dim co As Range
Set co = Cell.Offset(0, -2 * k)
Cell.Value = "=IFERROR(VLOOKUP(" & co & "," & ff & ",4,0),0)"
Next
End Sub