VBA: Autofill to last row not working

ObiWanBaloney

New Member
Joined
May 10, 2012
Messages
23
Code:
Sub ApplyVlookupFormulatoColumn()
'
' ApplyVlookupFormulatoColumn Macro
'


    ActiveCell = _
        "=IFERROR(VLOOKUP(E2,'ORDER TEMPLATE'!A:B,2,FALSE),0)"
    
    Dim lastrow As Long
     
    lastrow = Worksheets("ALL ITEMS").Range("A2").End(xlDown).Row
    With Worksheets("ALL ITEMS").Range(ActiveCell.Address)
[B]        .AutoFill Destination:=Range(ActiveCell.Address & lastrow&)[/B]
    End With
  
End Sub



Bolded part is not working. This is intended to work off whatever cell is selected, hence the activecell.address wherever it appears. Anyone know what to fix in this situation?
 

Excel Facts

Convert text numbers to real numbers
Select a column containing text numbers. Press Alt+D E F to quickly convert text to numbers. Faster than "Convert to Number"

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
.AutoFill Destination:=.Range(.Cells(ActiveCell.Row, ActiveCell.Column), .Cells(lastrow, ActiveCell.Column))
 

Rick Rothstein

MrExcel MVP
Joined
Apr 18, 2011
Messages
37,893
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Try

Rich (BB code):
.AutoFill Destination:=.Range(.Cells(ActiveCell.Row, ActiveCell.Column), .Cells(lastrow, ActiveCell.Column))
(Untested) If I am not mistaken, I think the red highlighted text could be replaced with just this...

ActiveCell.Address
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
You know that I like the verbose solutions Rick :)
 

ObiWanBaloney

New Member
Joined
May 10, 2012
Messages
23

ADVERTISEMENT

Thanks for the response guys! I'll definitely give it a try when I'm back to work =)
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650
Try

Code:
Sub ApplyVlookupFormulatoColumn()
'
' ApplyVlookupFormulatoColumn Macro
'


    ActiveCell.Formula = _
        "=IFERROR(VLOOKUP(E2,'ORDER TEMPLATE'!A:B,2,FALSE),0)"
    
    Dim lastrow As Long
     
    lastrow = Worksheets("ALL ITEMS").Range("A2").End(xlDown).Row
    With Worksheets("ALL ITEMS")
        ActiveCell.AutoFill Destination:=.Range(.Cells(ActiveCell.Row, ActiveCell.Column), .Cells(lastrow, ActiveCell.Column))
    End With
  
End Sub
 

ObiWanBaloney

New Member
Joined
May 10, 2012
Messages
23
Try

Code:
Sub ApplyVlookupFormulatoColumn()
'
' ApplyVlookupFormulatoColumn Macro
'


    ActiveCell.Formula = _
        "=IFERROR(VLOOKUP(E2,'ORDER TEMPLATE'!A:B,2,FALSE),0)"
    
    Dim lastrow As Long
     
    lastrow = Worksheets("ALL ITEMS").Range("A2").End(xlDown).Row
    With Worksheets("ALL ITEMS")
        ActiveCell.AutoFill Destination:=.Range(.Cells(ActiveCell.Row, ActiveCell.Column), .Cells(lastrow, ActiveCell.Column))
    End With
  
End Sub

Works! Thanks a bunch =D
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,652
Messages
5,838,610
Members
430,557
Latest member
MK15

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
Top