ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   AutoFilling To A Variable Number Of Rows (https://www.excelbanter.com/excel-programming/366208-autofilling-variable-number-rows.html)

Shing

AutoFilling To A Variable Number Of Rows
 

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

--
Shin
-----------------------------------------------------------------------
Shing's Profile: http://www.excelforum.com/member.php...fo&userid=3603
View this thread: http://www.excelforum.com/showthread.php?threadid=55822


excelent

AutoFilling To A Variable Number Of Rows
 
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


Shing[_2_]

AutoFilling To A Variable Number Of Rows
 

Thanks very much. That worked a treat.

Regards,
Wai Shing


--
Shing
------------------------------------------------------------------------
Shing's Profile: http://www.excelforum.com/member.php...o&userid=36031
View this thread: http://www.excelforum.com/showthread...hreadid=558222



All times are GMT +1. The time now is 02:11 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com