AutoFill Formula Issue in Table

crobinson661

New Member
Joined
Nov 15, 2019
Messages
11
Good Morning,

I have a macro that I am using to AutoFIll a VLOOKUP formula to the bottom of a table.

It keeps filling past the bottom of the table and creating new, expanding the table and creating blank rows, except the formula column of course has #N/A.

The issue is I am then converting this to a pivot and it picks up the blanks as a data point. :-/

I'm not sure how to prevent this. I'm familiar with how to write an autofill to max data range when a table is NOT included, but I don't see the same code and I anticipate it's because I'm using a table.

VBA Code:
Range("E1").Select
    ActiveCell.FormulaR1C1 = "Formula"
    Range("E2").Select
       Application.WindowState = xlMaximized
    Application.CutCopyMode = False
    Application.CutCopyMode = False
    ActiveCell.FormulaR1C1 = _
        "=VLOOKUP([@[Column D]],'[ReferenceFile.xlsx]Source Data - Per Item Pricing'!C1:C2,2,0)"

Any help would be appreciated.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
I can't seem to replicate this issue, could you upload the file somewhere and share a link? Maybe check the Pivot Tables Source?

This will work if not in a table.

VBA Code:
Sub InsertLookup()

Dim sht As Worksheet
Dim LastRow As Long

Set sht = ActiveSheet

LastRow = sht.Cells(sht.Rows.Count, "D").End(xlUp).Row

Range("E1") = "Formula"
Range("E2").FormulaR1C1 = _
        "=VLOOKUP(RC[-1],'[ReferenceFile.xlsx]Source Data - Per Item Pricing'!C1:C2,2,0)"
        
Range("E2").Copy Range("E2:E" & LastRow)
        

End Sub
 
Upvote 0

Forum statistics

Threads
1,215,061
Messages
6,122,921
Members
449,094
Latest member
teemeren

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