Excel Macro - Fill Down Formula

Hi,

I have the following macro which fill down the formula in cell F2 down to the last row of the table, working great... but.... on the same sheet, I also need to fill down formulas on Cell L2 and N2 down to the last row.

My Macro look like this:

Sub FillDownRAM()
    Sheets("Inventaire").Select
    Range("F2").Select
    If IsEmpty(ActiveCell) Then Exit Sub
    Range(ActiveCell, ActiveCell.Offset(0, -1).End(xlDown).Offset(0, 1)).FillDown
End Sub



But I'm a bit lost when it's time to add other column ....  Can you help?
mldaigle1Asked:
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.

Saurabh Singh TeotiaCommented:
You can use the following code to do what you are looking for..

Sub FillDownRAM()
    Dim lrow As Long
    lrow = Cells(Cells.Rows.Count, "a").End(xlUp).Row
    Sheets("Inventaire").Select

    Range("F2:F" & lrow).Formula = "Your formula here"
    

End Sub

Open in new window


Saurabh...
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Maybe this.....

Sub FillDownRAM()
    Sheets("Inventaire").Select
    If IsEmpty(Range("F2")) Then Exit Sub
    Range("F2", Range("F2").Offset(0, -1).End(xlDown).Offset(0, 1)).FillDown
    Range("L2", Range("L2").Offset(0, -7).End(xlDown).Offset(0, 1)).FillDown
    Range("N2", Range("N2").Offset(0, -9).End(xlDown).Offset(0, 1)).FillDown
End Sub

Open in new window

Roy CoxGroup Finance ManagerCommented:
You don't need VBA to do this. If your data is in a Table then make sure that you have formatted it as a Table. See

Overview of Excel Tables

You can even set autofill without a Table using Excel Options but the Table is best
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

mldaigle1Author Commented:
Hi Roy_Cox,

Presently, i am manually double-clicking to fill down the formulas every single time that I have to get the inventory.

Since this is a repeatitve task i was thinking of saving time by using an additional macro in that workbook since i am already using many macros.

:- /
mldaigle1Author Commented:
sktneer,

Unfortunately, it does not work.

Find attach a sample of the inventory.
inventory.xlsx
Saurabh Singh TeotiaCommented:
mldaigle1,

Did you try my approach of applying the formula directly??

Saurabh...
Roy CoxGroup Finance ManagerCommented:
You've missed the oint. An excel Table has calculated fields i.e. the formulas auto populate, read the article that I posted a link to.

I've edited your workbook to create a Table. Now select a cell in the last row and Tab throgh that Row , when you tab to the last cell it will automatically add a new row with all formulas
inventory.xlsx
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
What didn't work?

If copied the formula in F2, L2 and N2 down the rows. Please see attached.

Or am I missing something?
inventory.xlsm
Roy CoxGroup Finance ManagerCommented:
VBA is totally unnecessary in this case, see my attachment.

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
mldaigle1Author Commented:
Thanks Roy_Cox,

I will check more closely the article and the new file.

Thanks sktneer,
Your macro is not working fine when i change the offset to -1 everywhere

Have a great day Experts!!

:)

/mld.
Subodh Tiwari (Neeraj)Excel & VBA ExpertCommented:
Offset(0,-1) means, one column left to the active cell.

You're welcome mld!
Roy CoxGroup Finance ManagerCommented:
Check it out, you will find Tables are extremely useful when working with the data. Writing formulas is so much easier
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.