Formula fill down

D

dan

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!!!
 
D

Die_Another_Day

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

Charles
xl Geek
 
G

Gary Keramidas

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top