I have written an intense macro, that averages a row at a time from a beginning cell to an end cell.
The following line works fine:
ActiveCell.Formula = "=IF(" & BeginColFromAvgCEll & "="""","""",AVERAGE(" & BeginColFromAvgCEll & ":" & LastWorkingCell & "))"
However, I am now trying to change this to average only cells with non-zeros.
As many have experienced, when you have a total row with all zeros, it will bug out to only use AverageIF statement, so I was combining IfError statement to combat that.
I don't think there is an error in the statement, so there must be a rule that this doesn't fit or work within the confines of the rules in VBA.
But if typed directly in the cell it works. Recorded a R1C1 macro of this to see if I can convert it to VBA variables:
Recorded:
ActiveCell.FormulaR1C1 = _
"=IFERROR(AVERAGEIF(RC[-5]:RC[-1],"">0"",RC[-5]:RC[-1]),0)"
Trying to input (but VBA tells me error):
ActiveCell.Formula = "IFERROR(AVERAGEIF(" & BeginColFromAvgCEll & ":" & LastWorkingCell, & "">0"", BeginColFromAvgCEll & ":" & LastWorkingCell),0)"
ANY IDEAS??? thanks in advance!
Bookmarks