Forum Discussion

torchwood's avatar
torchwood
Copper Contributor
Dec 06, 2019
Solved

VBA; autofill down to a variable cell, but not overwriting already written numbers.

Hello   I'm really noobish to everything VBA (as in I can open the macrobox and thats it) so hoping there is someone willing to take some time to help me with a macro.   What I am looking for is ...
  • torchwood's avatar
    Aug 01, 2020

    torchwood 

    I finally found a bit of usefull code, so if anyone want the code here it is.

     

    Sub FillStuff()
    On Error Resume Next

    'I experience the code sometimes file an error, probably because E is in the marked area. so with this I make the code ignore possible errors and move on to the next line.


    Worksheets("Fyldeforløb").Activate

    'Fyldeforløb being the sheet I want it done to, with this you can make it autofill multiple sheets, just copy paste the whole piece and change the sheet name.


    With Range("C5:R" & Range("E" & Rows.Count).End(xlUp).Row)

    'C5 being the first cell in the area I need filled, and R being the last column. E is marking how far down the code will write. Example: I only got numbers in 6 rows of E then the code will only fill down to row E, and if I had 100 rows filled in E it would fill down to that last number.

     

    .SpecialCells(xlBlanks).FormulaR1C1 = "=R[-1]C"

    'This being the code that takes all blank cells and fill it with the value above

     

    .Value = .Value

    End With

    End sub

     

    With this I successfully managed to autofill 4 sheets without a problem.

    Also for those as noob as I am; the text I have put in with ' in front will have no effect on code, as it will register as notes (green text in the makro editor. So this should be plug and play.

Resources