ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Formula fill down (https://www.excelbanter.com/excel-programming/369123-formula-fill-down.html)

dan

Formula fill down
 
Hi,

I am using this part of a macro to enter a formula into J2 and then
fill it down. However, the amount of rows differs and I only want to
fill it down to the last row.

Range("J2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]24, ""Greater than 24 Hours"", ""Less than 24
Hours"")"
Range("I2:J701").Select
Selection.FillDown

How can I have it know what the last row is and stop there?

Thanks!!!


Die_Another_Day

Formula fill down
 
Change Range("I2:J701").Select to
Range("I2", Range("J2").End(xlDown)).Select

Charles
xl Geek
dan wrote:
Hi,

I am using this part of a macro to enter a formula into J2 and then
fill it down. However, the amount of rows differs and I only want to
fill it down to the last row.

Range("J2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]24, ""Greater than 24 Hours"", ""Less than 24
Hours"")"
Range("I2:J701").Select
Selection.FillDown

How can I have it know what the last row is and stop there?

Thanks!!!



Gary Keramidas

Formula fill down
 
how about something like this, without selecting anything?

Option Explicit
Sub test()
Dim LastRow As Long
LastRow = Worksheets("Sheet1").Cells(Rows.Count, "i").End(xlUp).Row

Range("J2").Formula = "=IF(i2 24, ""Greater than 24 Hours"", ""Less than 24
Hours"")"
Range("J2").AutoFill Range("j2:j" & LastRow)

End Sub

--


Gary


"dan" wrote in message
oups.com...
Hi,

I am using this part of a macro to enter a formula into J2 and then
fill it down. However, the amount of rows differs and I only want to
fill it down to the last row.

Range("J2").Select
ActiveCell.FormulaR1C1 = _
"=IF(RC[-1]24, ""Greater than 24 Hours"", ""Less than 24
Hours"")"
Range("I2:J701").Select
Selection.FillDown

How can I have it know what the last row is and stop there?

Thanks!!!





All times are GMT +1. The time now is 07:13 PM.

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