View Single Post
  #1   Report Post  
Posted to microsoft.public.excel.programming
scrabtree23[_3_] scrabtree23[_3_] is offline
external usenet poster
 
Posts: 55
Default Repeating formulas in VBA

Below is a sample of my code. You can see that all the "programing" is
designed to get the correct answer in cell "B7". I will need this formula to
repeat like 50 times with the only variables changing being MRRPYTo and the
MRRrange. How can I avoid all the lines of code and simply this? A second
question, if you use "IF Then End If" arguments in your VBA Code, when the
code is read to the If and the criteria are not met, does the reading skip
then until the line after the "End If" and pick up again there, or does it
still read through the code between the If and End If?

Dim MRRPYTo As Range
Set MRRPYTo = WSRep.Range("B7")

'When the unit is Provider (County Specific)
If UnVa.Value = "Provider" Then
BufYes.Value = WSDSD.Evaluate("=SUMPRODUCT((MRRrange=" &
ProVa & ")*(MRRrange<0)*(Yearrange=" & PaYrVa & ")*(Typerange=""" &
TyVa.Value & """)*(Locrange=""" & LocVa.Value & """))")
BufNo.Value = WSDSD.Evaluate("=SUMPRODUCT((MRRrange=" &
ProNoVa & ")*(MRRrange<0)*(Yearrange=" & PaYrVa & ")*(Typerange=""" &
TyVa.Value & """)*(Locrange=""" & LocVa.Value & """))")
BufTot.Value = BufYes.Value + BufNo.Value
MRRPYTo.Value = 0
If BufYes < 0 And BufTot < 0 Then
MRRPYTo.Value = BufYes.Value / (BufYes.Value +
BufNo.Value)
End If
End If