Copying a vlookup code on newly created document not working

Damian37

Active Member
Joined
Jun 9, 2014
Messages
301
Office Version
  1. 365
Hello everyone,
I'm attempting to use a vlookup formula within my VBA code. I recorded a macro and attempted to remove as much noise as I could. However I continue to receive a "Run-Time error '1004'
Application-defined or object-defined error. The code in bold red is the line of code that is being highlighted when debug is clicked on the error message.
Rich (BB code):
ub vlookup()
'
' vlookup Macro
'   SetWs = ActiveWorkbook.Worksheets("Sheet1")

'
    Set wkb2 = ActiveWorkbook.Worksheets("Sheet1")
    
    wkb2.Range("AE1").Value = "SMMO_EMAIL"
    ActiveCell.FormulaR1C1 = "SMMO EMAIL"
    wkb2.Range("AE2:AE").Select
    ActiveCell.FormulaR1C1 = _
        "=VLOOKUP(VALUE(RC[-30]),'[Mobile Stores - SMMO Listing.xlsx]Sheet1'!C1:C5,5,FALSE)"
    wkb2.Range("AE3").Select
    'Workbooks("Negative Replenishment file_" & Format(Date, "mm.dd.yyyy") & ".xlsx")
    LastRow = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    
    wkb2.Range("A2:AE" & LastRow).FillDown
End Sub
I'm trying to get the Vlookup formula to copy all the way down to the last row that has data. I appreciate any and all help I receive. Thank you.
D.
 

Excel Facts

Move date out one month or year
Use =EDATE(A2,1) for one month later. Use EDATE(A2,12) for one year later.
Try
Code:
Sub VLookup()
'
' vlookup Macro
'   SetWs = ActiveWorkbook.Worksheets("Sheet1")

'
    Set wkb2 = ActiveWorkbook.Worksheets("Sheet1")
    LastRow = wkb2.Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

    wkb2.Range("AE1").Value = "SMMO_EMAIL"
    wkb2.Range("AE2:AE" & LastRow).FormulaR1C1 = _
        "=VLOOKUP(VALUE(RC[-30]),'[Mobile Stores - SMMO Listing.xlsx]Sheet1'!C1:C5,5,FALSE)"
    'Workbooks("Negative Replenishment file_" & Format(Date, "mm.dd.yyyy") & ".xlsx")
    
End Sub
 
Upvote 0
Try
Code:
Sub VLookup()
'
' vlookup Macro
'   SetWs = ActiveWorkbook.Worksheets("Sheet1")

'
    Set wkb2 = ActiveWorkbook.Worksheets("Sheet1")
    LastRow = wkb2.Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row

    wkb2.Range("AE1").Value = "SMMO_EMAIL"
    wkb2.Range("AE2:AE" & LastRow).FormulaR1C1 = _
        "=VLOOKUP(VALUE(RC[-30]),'[Mobile Stores - SMMO Listing.xlsx]Sheet1'!C1:C5,5,FALSE)"
    'Workbooks("Negative Replenishment file_" & Format(Date, "mm.dd.yyyy") & ".xlsx")
    
End Sub

Hello Fluff,
Thank you very much that worked like a charm!
D.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,213,517
Messages
6,114,089
Members
448,548
Latest member
harryls

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