Kramerica44
New Member
- Joined
- May 30, 2013
- Messages
- 3
Hello all,
I have a VBA code I've used successfully to update formulas on a spread sheet once a week. This past week someone pointed out to me that in end of the month weeks 2 formulas were updated incorrectly. Once I corrected the R1C1 formulas, however, I started getting a run-time error (1004) even though the new formulas are substantially the same as the old ones and all the others that the macro generates. Here's a segment of the code with the broken lines and very similar formulas that work:
If Week = 10 Then
Range("AH15").Select
ActiveCell.FormulaR1C1 = _
"=RC[-21]+RC[-12]+sum(R[-4]C[-31]:RC[-31])-R[-5]C[-20]-R[-5]C[-19]-R[-5]C[-11]-RC[-10]-RC[-9]"
Range("AH19").Select
ActiveCell.FormulaR1C1 = _
"=RC[-21]+RC[-12]+sum(R[-3]C[-31]:RC[-31])-R[-4]C[-21]-R[-4]C[-12]-RC[-10]-RC[-9]"
....
Range("AH44").Select
ActiveCell.FormulaR1C1 = _
"=RC[-21]+RC[-12]+sum(R[-4]C[-31]:RC[-31])-R[-5]C[-20]-R[-5]C[-19]-R[-5]C[-11]-RC[-10]-RC[-9]"
Range("AH48").Select
ActiveCell.FormulaR1C1 = _
"=RC[-21]+RC[-12]+sum(R[-3]C[-31]:RC[-31])-R[-4]C[-21]-R[-4]C[-12]-RC[-10]-RC[-9]"
....
End If
The code won't run on the lines for AH15 and AH44, but works fine for AH19 and AH48. The only change to the formulas in AH15 and AH44 was "-R[-5]C[-20]-R[-5]C[-19]-R[-5]C[-11]" replaced "-R[-5]C[-21]-R[-5]C[-12]". Some other notes... This is one of many week number based if statements contained within a loop on all the sheets in the workbook. The macro uses an input box for the week number and then clears all relevant cells before entering any formulas. I updated the formulas for every end of month week and they all break at the two updated lines.
Thanks in advance for any and all attempts to help!
I have a VBA code I've used successfully to update formulas on a spread sheet once a week. This past week someone pointed out to me that in end of the month weeks 2 formulas were updated incorrectly. Once I corrected the R1C1 formulas, however, I started getting a run-time error (1004) even though the new formulas are substantially the same as the old ones and all the others that the macro generates. Here's a segment of the code with the broken lines and very similar formulas that work:
If Week = 10 Then
Range("AH15").Select
ActiveCell.FormulaR1C1 = _
"=RC[-21]+RC[-12]+sum(R[-4]C[-31]:RC[-31])-R[-5]C[-20]-R[-5]C[-19]-R[-5]C[-11]-RC[-10]-RC[-9]"
Range("AH19").Select
ActiveCell.FormulaR1C1 = _
"=RC[-21]+RC[-12]+sum(R[-3]C[-31]:RC[-31])-R[-4]C[-21]-R[-4]C[-12]-RC[-10]-RC[-9]"
....
Range("AH44").Select
ActiveCell.FormulaR1C1 = _
"=RC[-21]+RC[-12]+sum(R[-4]C[-31]:RC[-31])-R[-5]C[-20]-R[-5]C[-19]-R[-5]C[-11]-RC[-10]-RC[-9]"
Range("AH48").Select
ActiveCell.FormulaR1C1 = _
"=RC[-21]+RC[-12]+sum(R[-3]C[-31]:RC[-31])-R[-4]C[-21]-R[-4]C[-12]-RC[-10]-RC[-9]"
....
End If
The code won't run on the lines for AH15 and AH44, but works fine for AH19 and AH48. The only change to the formulas in AH15 and AH44 was "-R[-5]C[-20]-R[-5]C[-19]-R[-5]C[-11]" replaced "-R[-5]C[-21]-R[-5]C[-12]". Some other notes... This is one of many week number based if statements contained within a loop on all the sheets in the workbook. The macro uses an input box for the week number and then clears all relevant cells before entering any formulas. I updated the formulas for every end of month week and they all break at the two updated lines.
Thanks in advance for any and all attempts to help!