How can you you use a concatenated string as a command in VBA? The following code results in the following error:
Run-time error 424: Object required
Sub run()
Dim pic As Picture
Dim wks As Worksheet
Set wks = Sheets("Counter Party Select")
wks.Unprotect
Dim company As String
Dim sRange As String
Dim concate As String
Dim quote As String
Dim s1 As String
company = wks.Range("B3")
'This vlookup pulls the correct range based on the value
sRange = Application.VLookup(company, Sheets("Company Logos").Range("D3:E1000"), 2)
s1 = "Company Logos"
quote = Chr$(34) 'The character number of a quatation mark
Concat = "Sheets(" & quote & s1 & quote & ")." & sRange
'This results in Concat = "Sheets("Company Logos").Range("A146:A148")"
Concat.Copy 'The error occurs on this line
wks.Select
wks.Range("D2").Select
ActiveSheet.Paste
wks.Range("A1").Select
End Sub
How can I rewrite this code so that I can make the string an object and execute the .Copy command on it?
Dim Concat As RangeandSet Concat = WorkSheets("Company Logos").Range("A146:A148")Dim Concat As Range,Set Concat = Sheets("Company Logos").Range(Application.WorksheetFunction.VLookup(...)).Dim Concat As Range,Set Concat = Sheets(s1).Range(sRange), assumingsRangecontains"A146:A148". If your sheet (and thereforesRange) contains"Range("A146:A148")"in that second column, then fix it to only contain"A146:A148".