Hags2Rags
asked on
Excel Macro Question - Autofill formula
Hey everyone,
I am working on a macro in excel and I am having some issues with an autofill function. I am trying to autofill a formula for all rows that have a value in column C. My issue with my current macro is this....
when i recorded the macro, the macro recorded that i wanted to autofill the formula for cells D2:D539.
VBA code example:
ActiveCell.FormulaR1C1 = "=IF(ISBLANK(RC[-2]),R[-1] C,(RC[-2]) )"
Range("D2").Select
Selection.AutoFill Destination:=Range("D2:D53 9")
The number of rows will change each time I run this macro, could be more, could be less. That is why I would like to apply this formula to only cells where the Same row column C has a value. Is there a code i can type into this VBA string to help?
Thanks!
I am working on a macro in excel and I am having some issues with an autofill function. I am trying to autofill a formula for all rows that have a value in column C. My issue with my current macro is this....
when i recorded the macro, the macro recorded that i wanted to autofill the formula for cells D2:D539.
VBA code example:
ActiveCell.FormulaR1C1 = "=IF(ISBLANK(RC[-2]),R[-1]
Range("D2").Select
Selection.AutoFill Destination:=Range("D2:D53
The number of rows will change each time I run this macro, could be more, could be less. That is why I would like to apply this formula to only cells where the Same row column C has a value. Is there a code i can type into this VBA string to help?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dude, Chris. Thanks for the quick response. This is exactly what I was looking to do!
for r = 2 to 5000 'assumes you'll always have less than 5000 rows
if range("C" & r).value <> "" then range("D" & r).FormulaR1C1 = "=IF(ISBLANK(RC[-2]),R[-1]