saschmeling
New Member
- Joined
- Jun 27, 2012
- Messages
- 39
I am creating a VBA script that will use the following SumIf:
Range("C7").Select
ActiveCell.FormulaR1C1 = "=SUMIF(Sheet2!R[-6]C[-2]:R[515]C[7],1101,Sheet2!C)"
This continues on where C7 is the same but the If is different. I have to repeat this statement over 500 times. Unfortunately a basic loop won't work as the IF is program codes and there is no logical arrangement in this.
When I try to move to C8, the range must also change to be R[-7]C[-2]:R[514]C[7] as shown below.
Range("C8").Select
ActiveCell.FormulaR1C1 = "=SUMIF(Sheet2!R[-7]C[-2]:R[514]C[7],1102,Sheet2!C)"
I would like to use the following:
Dim MyRange As Range
Set MyRange = Worksheets("Sheet2").Range("A1:J512")
Then use a SumIf that refers to the named range as the range in the formula. When I try this, I get a Name error as though it is not recognizing the Range.
Any suggestions on how to do this?
Thanks,
Scott
Range("C7").Select
ActiveCell.FormulaR1C1 = "=SUMIF(Sheet2!R[-6]C[-2]:R[515]C[7],1101,Sheet2!C)"
This continues on where C7 is the same but the If is different. I have to repeat this statement over 500 times. Unfortunately a basic loop won't work as the IF is program codes and there is no logical arrangement in this.
When I try to move to C8, the range must also change to be R[-7]C[-2]:R[514]C[7] as shown below.
Range("C8").Select
ActiveCell.FormulaR1C1 = "=SUMIF(Sheet2!R[-7]C[-2]:R[514]C[7],1102,Sheet2!C)"
I would like to use the following:
Dim MyRange As Range
Set MyRange = Worksheets("Sheet2").Range("A1:J512")
Then use a SumIf that refers to the named range as the range in the formula. When I try this, I get a Name error as though it is not recognizing the Range.
Any suggestions on how to do this?
Thanks,
Scott