gheyman
Well-known Member
- Joined
- Nov 14, 2005
- Messages
- 2,347
- Office Version
- 365
- Platform
- Windows
What my code is supose to do is go down column E starting at row 9. If the value in Row E is "No" then it puts the first formula in column G. If Row E does not equal "No" then it puts the second formula in column G.
When I run it I dont get either formula in column G
Sub PriceSumFormula1()
'Put one of these formulas in Column G depending on value (Yes or No) in column E
'
Dim p As Long
Dim LastRow As Long
For p = 5 To LastRow
'
If Sheets("Pricing Summary").Cells(p, 5).Value = "No" Then
Sheets("Pricing Summary").Cells(p, 7).Select
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(SUMIF(INDIRECT(""A""&ROW()&"":A""&IF(COUNTIF(R[1]C1:R1003C1,RC1),MATCH(RC1,R[1]C1:R1003C1,0)+ROW(RC1),1003)),RC1+1,INDIRECT(""G""&ROW()&"":G""&IF(COUNTIF(R[1]C1:R1003C1,RC1),MATCH(RC1,R[1]C1:R1003C1,0)+ROW(RC1),1003)))),"""",SUMIF(INDIRECT(""A""&ROW()&"":A""&IF(COUNTIF(R[1]C1:R1003C1,RC1),MATCH(RC1,R[1]C1:R1003C1,0)+ROW(RC1),1003)),RC1+1,INDIRECT(""G""&ROW()&"":G""&IF(COUNTIF(R[1]C1:R1003C1,RC1),MATCH(RC1,R[1]C1:R1003C1,0)+ROW(RC1),1003))))"
Else
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(INDIRECT(RC2&""!F82"")),"""",INDIRECT(RC2&""!F82""))"
'
'
End If
'
Next p
'
End Sub
When I run it I dont get either formula in column G
Sub PriceSumFormula1()
'Put one of these formulas in Column G depending on value (Yes or No) in column E
'
Dim p As Long
Dim LastRow As Long
For p = 5 To LastRow
'
If Sheets("Pricing Summary").Cells(p, 5).Value = "No" Then
Sheets("Pricing Summary").Cells(p, 7).Select
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(SUMIF(INDIRECT(""A""&ROW()&"":A""&IF(COUNTIF(R[1]C1:R1003C1,RC1),MATCH(RC1,R[1]C1:R1003C1,0)+ROW(RC1),1003)),RC1+1,INDIRECT(""G""&ROW()&"":G""&IF(COUNTIF(R[1]C1:R1003C1,RC1),MATCH(RC1,R[1]C1:R1003C1,0)+ROW(RC1),1003)))),"""",SUMIF(INDIRECT(""A""&ROW()&"":A""&IF(COUNTIF(R[1]C1:R1003C1,RC1),MATCH(RC1,R[1]C1:R1003C1,0)+ROW(RC1),1003)),RC1+1,INDIRECT(""G""&ROW()&"":G""&IF(COUNTIF(R[1]C1:R1003C1,RC1),MATCH(RC1,R[1]C1:R1003C1,0)+ROW(RC1),1003))))"
Else
ActiveCell.FormulaR1C1 = _
"=IF(ISERROR(INDIRECT(RC2&""!F82"")),"""",INDIRECT(RC2&""!F82""))"
'
'
End If
'
Next p
'
End Sub