I created a macro that puts a formula into I2 of a spreadsheet, and fills it down until the last non-empty row, then it should stop. I had it working, but had to make a couple of adjustments, now it fills down to 1M+ rows. I've made adjustments for hours and can't seem to figure out where my syntax is off. . .
Sub CopyFunctionI()
Range("I2").Formula = "=IF(TYPE($I1)=2,$H2,($H2+$I1))"
Range("I2").AutoFill Destination:=Range("$I$2:$I$" & Cells(Rows.Count, 6).End(xlDown).Row)
End Sub
I tried using ".End(xlUp)" which is how I had it working originally, but it keeps trying to put the first entry into I1, which is where the column header is, and since the formula is looking for a previous cell's value, it errors.
I also am trying to do this same type of function for column J, that takes the value in column I and divides by the sum of all values in column H (a running % of total). But I haven't been successful getting the formula to divide by the sum when I use a range. Any ideas there, too?
Can someone help please.
Sub CopyFunctionI()
Range("I2").Formula = "=IF(TYPE($I1)=2,$H2,($H2+$I1))"
Range("I2").AutoFill Destination:=Range("$I$2:$I$" & Cells(Rows.Count, 6).End(xlDown).Row)
End Sub
I tried using ".End(xlUp)" which is how I had it working originally, but it keeps trying to put the first entry into I1, which is where the column header is, and since the formula is looking for a previous cell's value, it errors.
I also am trying to do this same type of function for column J, that takes the value in column I and divides by the sum of all values in column H (a running % of total). But I haven't been successful getting the formula to divide by the sum when I use a range. Any ideas there, too?
Can someone help please.