SOLVED

How to autofill multiple formulas with a range that is down to the last cell of a certain column?

%3CLINGO-SUB%20id%3D%22lingo-sub-1305118%22%20slang%3D%22en-US%22%3EHow%20to%20autofill%20multiple%20formulas%20with%20a%20range%20that%20is%20down%20to%20the%20last%20cell%20of%20a%20certain%20column%3F%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1305118%22%20slang%3D%22en-US%22%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EHi%20there%2C%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EI'm%20trying%20to%20run%205%20basic%20formulas%20in%20one%20macro%3A%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EActiveCell.FormulaR1C1%20%3D%20%22%3DLOOKUP(RC28%2CTable1)%22%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EActiveCell.FormulaR1C1%20%3D%20%22%3DWEEKNUM(RC27)%22%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EActiveCell.FormulaR1C1%20%3D%20%22%3DWEEKDAY(RC27)%22%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EActiveCell.FormulaR1C1%20%3D%20%22%3DIF(RC10%26gt%3B0%2C%22%22W%22%22%2CIF(0%26gt%3BRC10%2C%22%22L%22%22%2C%22%22F%22%22))%22%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EActiveCell.Formula2R1C1%20%3D%20%22%3D(ABS)(RC5-RC36)%22%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3EThese%20formulas%20all%20run%20in%20different%20columns.%20I%20need%20them%20to%20fill%20the%20formula%20down%20in%20their%20respective%20columns%2C%20from%20the%20start%20of%20NEW%20data%20in%20column%20A%20(starting%20at%20A4)%20to%20the%20end%20of%20NEW%20data%20in%20column%20A.%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3ESo%20basically%20the%20formula%20shouldn't%20run%20in%20cells%20in%20its%20column%20that%20are%20already%20filled%2C%20with%20the%20end%20of%20thedata%20in%20column%20A%20being%20the%20cut%20off.%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22plbetbu86rs41.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F184207i4D3587A2B51C6D76%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22plbetbu86rs41.png%22%20alt%3D%22plbetbu86rs41.png%22%20%2F%3E%3C%2FSPAN%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20image-alt%3D%22p98ykvr97rs41.png%22%20style%3D%22width%3A%20400px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F184208iBE1EE3C7F875343A%2Fimage-size%2Fmedium%3Fv%3D1.0%26amp%3Bpx%3D400%22%20title%3D%22p98ykvr97rs41.png%22%20alt%3D%22p98ykvr97rs41.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%26nbsp%3B%3C%2FP%3E%3CP%20class%3D%22_1qeIAgB0cPwnLhDF9XSiJM%22%3E%3CSPAN%3EThanks%20very%20much%20in%20advance!%20Have%20been%20struggling%20a%20lot%20with%20this%20%3CLI-EMOJI%20id%3D%22lia_disappointed-face%22%20title%3D%22%3Adisappointed_face%3A%22%3E%3C%2FLI-EMOJI%3E%3C%2FSPAN%3E%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-LABS%20id%3D%22lingo-labs-1305118%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3EExcel%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EFormulas%20and%20Functions%3C%2FLINGO-LABEL%3E%3CLINGO-LABEL%3EMacros%20and%20VBA%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1306006%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20autofill%20multiple%20formulas%20with%20a%20range%20that%20is%20down%20to%20the%20last%20cell%20of%20a%20certain%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1306006%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F620693%22%20target%3D%22_blank%22%3E%40Naan_Deal%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EDifficult%20to%20help%20on%20developing%20a%20macro%20without%20the%20file%20on%20hand%2C%20but%20I%20have%20actually%20done%20something%20similar%20in%20the%20real%20world%20for%20a%20client.%20It%20involves%20a%20named%20range%2C%20a%20piece%20of%20code%20with%20%22Currentregion%22%20to%20count%20the%20number%20of%20rows%20that%20the%20formulae%20need%20to%20be%20copied%20to.%20Not%20very%20difficult%2C%20but%20depends%20a%20little%20bit%20the%20structure%20of%20your%20sheet.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ECan%20you%20upload%20your%20file%3F%20Don't%20need%20the%20macro%2C%20just%20the%20structure.%20Will%20take%20the%20formulae%20from%20you%20original%20post.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1306059%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20autofill%20multiple%20formulas%20with%20a%20range%20that%20is%20down%20to%20the%20last%20cell%20of%20a%20certain%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1306059%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3BHi%20Riny%20-%20thank%20you%20so%20much%20for%20replying!%20The%20file%20is%20attached.%20The%20sheet%20in%20question%20is%20the%20%22Trade%20Log%22%20sheet.%20I'll%20need%20to%20do%20the%20same%20thing%20for%20the%20text%20to%20columns%20stuff%20in%20there%20as%20well.%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1306131%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20autofill%20multiple%20formulas%20with%20a%20range%20that%20is%20down%20to%20the%20last%20cell%20of%20a%20certain%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1306131%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F620693%22%20target%3D%22_blank%22%3E%40Naan_Deal%3C%2FA%3E%26nbsp%3BAlmost%20diner%20time%20in%20my%20part%20of%20the%20world.%20Give%20me%20some%20time.%20Will%20get%20back%20to%2C%20if%20not%20someone%20else%20does.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1306147%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20autofill%20multiple%20formulas%20with%20a%20range%20that%20is%20down%20to%20the%20last%20cell%20of%20a%20certain%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1306147%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3BNo%20problem%20at%20all%2C%20thank%20you%20very%20much%20again%20for%20taking%20a%20look%20at%20it%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1308174%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20autofill%20multiple%20formulas%20with%20a%20range%20that%20is%20down%20to%20the%20last%20cell%20of%20a%20certain%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1308174%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F620693%22%20target%3D%22_blank%22%3E%40Naan_Deal%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EThis%20piece%20of%20code%20will%20enter%20the%20formulae%20in%20AC%2C%20AG%3AAI%20and%20AL%20and%20copy%20them%20down%20until%20the%20last%20row.%20Note%20I%20changed%20the%20formula%20in%20AL%20as%20the%20one%20you%20provided%20%26nbsp%3B(%3CSTRONG%3E%3CFONT%20color%3D%22%23FF0000%22%3E%3D(ABS)(RC5-RC36)%3C%2FFONT%3E%3C%2FSTRONG%3E%3CFONT%20color%3D%22%23FF0000%22%3E%3CFONT%20color%3D%22%23000000%22%3E)%20didn't%20seem%20to%20be%20correct.%3C%2FFONT%3E%3C%2FFONT%3E%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3ESub%20CopyFormulae()%0A%20%0ADim%20EndRow%20As%20Integer%0AEndRow%20%3D%20Sheets(%22Trade%20Log%22).Range(%22A1%22).CurrentRegion.Rows.Count%0A%0ARange(%22AC4%22).FormulaR1C1%20%3D%20%22%3DLOOKUP(RC28%2CTable1)%22%0ARange(%22AC4%22).Select%0ASelection.Copy%0ARange(%22AC5%22%20%26amp%3B%20%22%3AAC%22%20%26amp%3B%20EndRow).Select%0AActiveSheet.Paste%0A%0ARange(%22AG4%22).FormulaR1C1%20%3D%20%22%3DWEEKNUM(RC27)%22%0ARange(%22AH4%22).FormulaR1C1%20%3D%20%22%3DWEEKDAY(RC27)%22%0ARange(%22AI4%22).FormulaR1C1%20%3D%20%22%3DIF(RC10%26gt%3B0%2C%22%22W%22%22%2CIF(0%26gt%3BRC10%2C%22%22L%22%22%2C%22%22F%22%22))%22%0ARange(%22AG4%3AAI4%22).Select%0ASelection.Copy%0ARange(%22AG5%22%20%26amp%3B%20%22%3AAI%22%20%26amp%3B%20EndRow).Select%0AActiveSheet.Paste%0A%0ARange(%22AL4%22).FormulaR1C1%20%3D%20%22%3DABS(RC5-RC36)%22%0ARange(%22AL4%22).Select%0ASelection.Copy%0ARange(%22AL5%22%20%26amp%3B%20%22%3AAL%22%20%26amp%3B%20EndRow).Select%0AActiveSheet.Paste%0A%0AApplication.CutCopyMode%20%3D%20False%0A%0AEnd%20Sub%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1308615%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20autofill%20multiple%20formulas%20with%20a%20range%20that%20is%20down%20to%20the%20last%20cell%20of%20a%20certain%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1308615%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F403176%22%20target%3D%22_blank%22%3E%40Riny_van_Eekelen%3C%2FA%3E%26nbsp%3BI%20cannot%20thank%20you%20enough%20Riny.%20I'm%20really%20really%20grateful.%20Thank%20you%20so%20much!%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-1308631%22%20slang%3D%22en-US%22%3ERe%3A%20How%20to%20autofill%20multiple%20formulas%20with%20a%20range%20that%20is%20down%20to%20the%20last%20cell%20of%20a%20certain%20column%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-1308631%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F620693%22%20target%3D%22_blank%22%3E%40Naan_Deal%3C%2FA%3E%26nbsp%3BMost%20welcome!%3C%2FP%3E%3C%2FLINGO-BODY%3E
New Contributor

Hi there,

 

I'm trying to run 5 basic formulas in one macro:

ActiveCell.FormulaR1C1 = "=LOOKUP(RC28,Table1)"

ActiveCell.FormulaR1C1 = "=WEEKNUM(RC27)"

ActiveCell.FormulaR1C1 = "=WEEKDAY(RC27)"

ActiveCell.FormulaR1C1 = "=IF(RC10>0,""W"",IF(0>RC10,""L"",""F""))"

ActiveCell.Formula2R1C1 = "=(ABS)(RC5-RC36)"

 

These formulas all run in different columns. I need them to fill the formula down in their respective columns, from the start of NEW data in column A (starting at A4) to the end of NEW data in column A.

So basically the formula shouldn't run in cells in its column that are already filled, with the end of thedata in column A being the cut off.

plbetbu86rs41.pngp98ykvr97rs41.png

 

Thanks very much in advance! Have been struggling a lot with this

7 Replies
Highlighted

@Naan_Deal 

Difficult to help on developing a macro without the file on hand, but I have actually done something similar in the real world for a client. It involves a named range, a piece of code with "Currentregion" to count the number of rows that the formulae need to be copied to. Not very difficult, but depends a little bit the structure of your sheet.

 

Can you upload your file? Don't need the macro, just the structure. Will take the formulae from you original post.

 

 

 

 

Highlighted

@Riny_van_Eekelen Hi Riny - thank you so much for replying! The file is attached. The sheet in question is the "Trade Log" sheet. I'll need to do the same thing for the text to columns stuff in there as well. 

Highlighted

@Naan_Deal Almost diner time in my part of the world. Give me some time. Will get back to, if not someone else does.

Highlighted

@Riny_van_Eekelen No problem at all, thank you very much again for taking a look at it

Highlighted
Best Response confirmed by Naan_Deal (New Contributor)
Solution

@Naan_Deal 

This piece of code will enter the formulae in AC, AG:AI and AL and copy them down until the last row. Note I changed the formula in AL as the one you provided  (=(ABS)(RC5-RC36)) didn't seem to be correct.

Sub CopyFormulae()
 
Dim EndRow As Integer
EndRow = Sheets("Trade Log").Range("A1").CurrentRegion.Rows.Count

Range("AC4").FormulaR1C1 = "=LOOKUP(RC28,Table1)"
Range("AC4").Select
Selection.Copy
Range("AC5" & ":AC" & EndRow).Select
ActiveSheet.Paste

Range("AG4").FormulaR1C1 = "=WEEKNUM(RC27)"
Range("AH4").FormulaR1C1 = "=WEEKDAY(RC27)"
Range("AI4").FormulaR1C1 = "=IF(RC10>0,""W"",IF(0>RC10,""L"",""F""))"
Range("AG4:AI4").Select
Selection.Copy
Range("AG5" & ":AI" & EndRow).Select
ActiveSheet.Paste

Range("AL4").FormulaR1C1 = "=ABS(RC5-RC36)"
Range("AL4").Select
Selection.Copy
Range("AL5" & ":AL" & EndRow).Select
ActiveSheet.Paste

Application.CutCopyMode = False

End Sub

 

Highlighted

@Riny_van_Eekelen I cannot thank you enough Riny. I'm really really grateful. Thank you so much!

Highlighted