AutoFilling To A Variable Number Of Rows

  • Thread starter Thread starter Shing
  • Start date Start date
S

Shing

I'm new to programming in VBA so please have some patience with m
ignorance.

I am trying write some VBA code to AutoFill a column with a formula
Normally, I can just use:

Range("C1").Select
ActiveCell.FormulaR1C1 = "=RC[-2]/RC[-1]"
Range("C1").Select
Selection.AutoFill Destination:=Range("C1:C10"), Type:=xlFillDefault
Range("C1:C10").Select

The problem is, the number of rows is variable so I don't want to se
the number of rows finitely to 10.

How can I AutoFill the column to the number of rows that matches th
number of rows of data? I know there is an END property that exists
Can I use that?

Any help is greatly appreciated. Thanks in advance.

Regards,
Wai Shin
 
Sub tst()
' find first non emty cells in column A from bottom up (r)
r = Cells(65500, 1).End(xlUp).Row

Range("C1").Select
ActiveCell.FormulaR1C1 = "=RC[-2]/RC[-1]"
Range("C1").Select
Selection.AutoFill Destination:=Range("C1:C" & r), Type:=xlFillDefault

End Sub
 
Back
Top