Hi. I am trying to store a variable (I will highlight it in red below) to be used later in the same formula. The formula I have now works, but it puts the variable in cell G20, and I do not need this variable anywhere on the sheet. However, I do need it to perform some calculations later in the code. Here is the code:
Sub y()
Dim c As Range, lrow As Long
lrow = Sheet1.Cells(Rows.Count, 1).End(xlUp).Row
Application.ScreenUpdating = False
For Each c In Sheet1.Range("A2:A29" & lrow)
If c.Value = "Mike" And c.Offset(0, 1).Value = "Fax" Then
Range("G20").Value = Range("G20") + c.Offset(0, 3).Value
End If
Next c
Range("G21").Formula = "=$G$20 / SUMPRODUCT(--(A2:A29=""Mike""),--(B2:B29=""Fax""))"
Application.ScreenUpdating = True
End Sub
As you can see, in order to get G21, I am using the value from G20. Ideally, I want to be able to calculate G21 without G20 being visible. So instead of my code saving this number in G20, is there a way for the code to remember or store the value (of G20) to be used in the following formula (bottom of top code):
Range("G21").Formula = "=$G$20 / SUMPRODUCT(--(A2:A29=""Mike""),--(B2:B29=""Fax""))"
Bookmarks