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

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Try

Code:
.AutoFill Destination:=.Range(.Cells(ActiveCell.Row, ActiveCell.Column), .Cells(lastrow, ActiveCell.Column))
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,215,693
Messages
6,126,246
Members
449,304
Latest member
hagia_sofia

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