Hi all , I wrote code that works just fine, however, I realized there were parts of the data I was using that had 0's in it for holiday.
Bottom line, this is code that calculated the weighted average of prices for 12 months (12 rows across) and Drows across. I'm trying to use the "do while is empty" approach but can't get the syntax to work. Here's the code
Bottom line, this is code that calculated the weighted average of prices for 12 months (12 rows across) and Drows across. I'm trying to use the "do while is empty" approach but can't get the syntax to work. Here's the code
Code:
For r = 1 To drows
Totwavg = 0
Tothours = 0
priceavg = 0
For n = 1 To ncontracts
Do While IsEmpty(rngs.Cells(r, n + 1))
If r > drows Then Exit Do
Hours = Application.VLookup(PWR.Cells(1, n + 1).Value, vHours, 1 + OnOff1, False)
priceavg = PWR.Cells(1 + r, n + 1).Value * Hours
Totwavg = Totwavg + priceavg
Hoursbucket = 0
Hoursbucket = Application.VLookup(PWR.Cells(1, 1 + n).Value, vHours, 1 + OnOff1, False)
Tothours = Tothours + Hoursbucket
Next n
Worksheets("INFO").Cells(1 + r, 2).Value = Totwavg / Tothours
End If
Loop
Next r