PDA

View Full Version : [SOLVED] Drag a formula down to the end of a list



ChrisKad
08-19-2015, 08:13 AM
Hi,

I have this formula :

Range("I3").Formula = "=IF(C3=C2,0,1)"

How can I drag it down to automatically fill all the cells until the last row?

The number of rows I have differs weekly so I need to get a code that drags the formula down automatically to the last cell on the list.

Any help will be appreciated :)

Thank you.

Chris

mancubus
08-19-2015, 01:26 PM
try:



With Worksheets("Sheet1") 'change workheet name to suit
LastRow = .Range("C" & .Rows.Count).End(xlUp).Row
.Range("I3:I" & LastRow).Formula = "=IF(C3=C2,0,1)"
End With


or, without using a variable


With Worksheets("Sheet1") 'change workheet name to suit
.Range("I3:I" & .Range("C" & .Rows.Count).End(xlUp).Row).Formula = "=IF(C3=C2,0,1)"
End With

snb
08-19-2015, 02:04 PM
You don't need to if you use the Table /Listobject (Excel >2003)

ChrisKad
08-27-2015, 03:15 AM
Thank you so much!! It works :)