Guest_imported
New member
- Jan 1, 1970
- 0
I need to use the Average function on data that sometimes will wind up being all blanks (user hasn't entered that range yet). Apprently, this causes an error message.
Is there a way to specify the function so it ignores blanks and avoids the error? I know that ON ERROR RESUME NEXT will skip the error prone statement and is useful, but curious if there's some parameter that can be used with the function. Here's how I did it in the meantime...sure there's probably a more elegant streamlined method:
'COUNTING NUMBER OF NON-BLANK CELLS IN NEWRANGE
ActiveCell.Formula = "=CountA(" & newrange & "
"
'MAKING SURE THE RESULT IS A VALUE, NOT FORMULA
ActiveCell.Value = ActiveCell.Value
'DOES FORMULA IF RANGE IS NOT ALL BLANKS
If ActiveCell.Value > 0 Then
ActiveCell.Formula = "=Average(" & newrange & "
"
Else
ActiveCell.Value = ""
End If
'MAKES SURE RESULT IS VALUE, NOT FORMULA
ActiveCell.Value = ActiveCell.Value
Is there a way to specify the function so it ignores blanks and avoids the error? I know that ON ERROR RESUME NEXT will skip the error prone statement and is useful, but curious if there's some parameter that can be used with the function. Here's how I did it in the meantime...sure there's probably a more elegant streamlined method:
'COUNTING NUMBER OF NON-BLANK CELLS IN NEWRANGE
ActiveCell.Formula = "=CountA(" & newrange & "
'MAKING SURE THE RESULT IS A VALUE, NOT FORMULA
ActiveCell.Value = ActiveCell.Value
'DOES FORMULA IF RANGE IS NOT ALL BLANKS
If ActiveCell.Value > 0 Then
ActiveCell.Formula = "=Average(" & newrange & "
Else
ActiveCell.Value = ""
End If
'MAKES SURE RESULT IS VALUE, NOT FORMULA
ActiveCell.Value = ActiveCell.Value