Macros Formula Creates Error in Entire Column

chiepet

New Member
Joined
Jul 25, 2013
Messages
2
Hello. So I've been stuck with this problem for quite some time now. I created a formula using macros and applied it to an entire column in my spreadsheet. However, once I edit the value of some other cell the macros references to OR delete a row anywhere in the sheet, all the cells that use that macros turns into 0 or #value!. But once I click through the cells in the column and press enter or do F2+Enter it returns to its correct value.

I've checked the settings so the file automatically calculates every time the spreadsheet is updated, I've tried "Text To Columns" and updating the entire column, I've tried Ctrl+Alt+F9, I've also copied everything and created a new doc in case the older one was corrupted or something but none of these methods give me the right solution.
I'd appreciate any sort of help at this point. Thanks.
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
Thank you Smitty!

My code is here:

Function TotalAvg(Rate As Double, Cell As String) As Double
Dim iRow As Integer, numValues As Integer
Dim numTotal As Currency, Total As Currency

iRow = ActiveCell.Row
numValues = 1
numTotal = 1
Do Until (Cells(iRow + 1, 3).Value <> 0)
iRow = iRow + 1
numTotal = numTotal + 1
Loop
Total = Cells(iRow, 2).Value
Do While (numTotal > 1 And DateDiff("yyyy", Cells(iRow, 4).Value, Cells(iRow - 1, 4).Value) = 0)
numValues = numValues + 1
Total = Total + Cells(iRow - 1, 2).Value
iRow = iRow - 1
Loop
TotalAvg = Total / numValues
End Function
 
Upvote 0

Forum statistics

Threads
1,214,925
Messages
6,122,298
Members
449,077
Latest member
Rkmenon

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