VBA - object required

p4nny

Board Regular
Joined
Jan 13, 2015
Messages
246
Hi

Please could you help, I'm getting an "object required error" on this following code:

Would appreciate any guidance. Thank you

Code:
Sub PopulateColumns()




  Dim ws As Worksheet
  Dim inputmonth As String
  
  inputmonth = InputBox("Enter CRA Reporting Month")
     
    For Each ws In ActiveWorkbook.Sheets
        ws.Activate
    
    ws.Range("k6") = "BIM Area"
    ws.Range("K7:k14") = Application.WorksheetFunction.VLookup(ActiveSheet.Name, Lookup.Range("a$1$:B$200$"), 2, 0)
    ws.Range("L6") = "Date"
    ws.Range("l7:l14") = inputmonth
    Next ws


End Sub
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
What exactly is the "Lookup" referenced here?
Code:
ws.Range("K7:k14") = Application.WorksheetFunction.VLookup(ActiveSheet.Name, [COLOR=#ff0000][B]Lookup[/B][/COLOR].Range("a$1$:B$200$"), 2, 0)
It looks like it is set-up to be an object (maybe a worksheet object), but I do not see it being defined anywhere.
 
Upvote 0
OK, but you are not using it that way in your code. Currently, it is an unassigned object.
You either need to define a worksheet object and set it equal to "LOOKUP" to use it like that, or you need to do something like:
Code:
Sheets("LOOKUP").[COLOR=#333333]Range("A$1$:B$200$")[/COLOR]
 
Upvote 0
You have the $ signs in the wrong place. If "Lookup" is the sheet codename try
Code:
Lookup.Range("$a$1:$B$200")
 
Upvote 0

Forum statistics

Threads
1,224,820
Messages
6,181,162
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top