Enter header and formula, copy down column

Cheers!
Attached is sample workbook.

On sheet Filtered_Data, I need macro to enter header into the first empty column.
This column may vary, so it must be dynamic - first empty column, Row1.
Header - "Ground Rates"

In that column, Row 2, I need the following formula entered and copied down the column.
=IF($D2>=150,(VLOOKUP($D2,GR,$L2,TRUE)/150)*$D2,VLOOKUP($D2,GR,$L2,FALSE))

Open in new window


Thanks!
MWT-TOOL-v4.xlsm
Euro5Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
Try this....

Sub InsertFormula()
    Dim NextCol As Long, LastRow As Long
    With Filtered_Data
        NextCol = .Cells(1, Columns.Count).End(xlToLeft).Column + 1
        LastRow = .Cells(Rows.Count, "A").End(xlUp).Row
        .Cells(1, NextCol) = "Ground Rates"
        .Range(.Cells(2, NextCol), .Cells(LastRow, NextCol)).FormulaR1C1 = "=IF(RC4>=150,(VLOOKUP(RC4,GR,RC12,TRUE)/150)*RC4,VLOOKUP(RC4,GR,RC12,FALSE))"
    End With
End Sub

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Euro5Author Commented:
Perfect thanks!!! :)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.