Where's Waldo (AKA the Problem)

gheyman

Well-known Member
Joined
Nov 14, 2005
Messages
2,347
Office Version
  1. 365
Platform
  1. 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
 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
You're not initializing lastrow, so it's zero, so the code in the loop never executes.
 
Upvote 0
Can you elaborate. I am self taught and not that technical with VBA yet.

Thanks
 
Upvote 0
You have to tell Excel how to 1) calculate what the LastRow is or 2) just tell it what number it is
 
Upvote 0
now I see!

Dim LastRow As Long

With Sheets("Pricing Summary")
LastRow = .Cells(.Rows.Count, 1).End(xlUp).Row
End With

Thanks for simplifing that. Much appreciated
 
Upvote 0
Still have a problem. I fixed the problem with identifying the LastRow. But the code still doesnt perfrom as I intended. It is running through each cell down column E. But is only putting formulas in some of the cell in column G. Its only putting formulas in where E = No. Even then its not always putting in the correct formula of the two in the code.

If E = No then insert the first formula in the code. If E <> No then put in the second formula.

The code seems to make sense to me.

If Sheets("Pricing Summary").Cells(p, 5).Value = "No" Then
Sheets("Pricing Summary").Cells(p, 7).Select
ActiveCell.FormulaR1C1 = XYZ
Else
ActiveCell.FormulaR1C1 = ABC

WHAT AM I MISSING????????
 
Upvote 0

Forum statistics

Threads
1,224,574
Messages
6,179,633
Members
452,933
Latest member
patv

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top