I have a excel macro which reads content from a specific column in another sheet. I want to use a variable in the sheet name in a WITH statement but keep getting an error message "Error during runtime, Object required" in the For Each line
I already searched how to use variables in object names and tried that, but to no avail.
This code works
With Blad2
strData = Range(id & "1") & vbLf & vbLf
For Each c In .Range(id & "2:" & id & "10")
If c.Value <> "" Then
strData = strData & " - " & c.Value & vbLf
End If
Next c
End With
This code fails. I know for sure variable bld has a numeric value, tested that with MsgBox
With ("Blad" & bld)
strData = Range(id & "1") & vbLf & vbLf
For Each c In .Range(id & "2:" & id & "10")
If c.Value <> "" Then
strData = strData & " - " & c.Value & vbLf
End If
Next c
End With
Any clues how I can get this to work?