Link to home
Start Free TrialLog in
Avatar of mldaigle1
mldaigle1Flag for Canada

asked on

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?
Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

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...
SOLUTION
Avatar of Subodh Tiwari (Neeraj)
Subodh Tiwari (Neeraj)
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of mldaigle1

ASKER

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.

:- /
sktneer,

Unfortunately, it does not work.

Find attach a sample of the inventory.
inventory.xlsx
mldaigle1,

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

Saurabh...
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
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
ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
Offset(0,-1) means, one column left to the active cell.

You're welcome mld!
Check it out, you will find Tables are extremely useful when working with the data. Writing formulas is so much easier