VBA Auto fill formula help

Copper Contributor

Hi guys I need help with a macro I’m creating this is what I have so far

 

Range(“J2”).Select

ActiveCell.FormulaR1C1 = “=IFERROR(RC[-1]/RC[-2],0)”

Range(“J2”).Select

Range(“J2”).AutoFill Range(“J2:J2000”)

 

I just put J2000 for now but I would like it to stop as soon as there is no more data to divide. There’s some adjacent cells that could be blank though, so I don’t want it to stop on those parts however I was it to stop wherever the total row is hit. Any help will be appreciated

1 Reply

@moczare 

Please don't use curly quotes “ ” around text strings in VBA. Always use straight quotes " ".

    Dim LastRow As Long
    LastRow = Cells.Find(What:="*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
    Range("J2:J" & LastRow).FormulaR1C1 = "=IFERROR(RC[-1]/RC[-2],0)"