Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
 
Posts: n/a
Default Sumif to return a blank if sum range is blank

Thanks for your answers. In the end I decided that writing my own
replacement VBA function for SUMIF would be the simplest way (I have
some hefty formulas to put in the middle of this sumif function
anyway). For completeness I've posted the code below.

Public Function SumIfNB(rngSource As Range, vMatchVal As Variant,
rngSum As Range) As Variant
'This functions works like sumif but with one exception.
'If all matching values in the row to sum are blank it returns blank
On Error GoTo ErrHe
Dim i As Long
Dim vSum As Variant
Dim bAllBlank As Boolean
bAllBlank = True

For i = 1 To rngSource.Cells.Rows.Count - 1
If rngSource.Cells(i, 1).Value < "" Then
If rngSource.Cells(i, 1).Value = vMatchVal Then
If rngSum.Cells(i, 1).Value < "" Then
bAllBlank = False
vSum = vSum + rngSum.Cells(i, 1).Value
End If
End If
End If
Next i

If bAllBlank = True Then
SumIfNB = ""
Else
SumIfNB = vSum
End If
ExitHe
Exit Function

ErrHe
MsgBox Err.Description
Resume ExitHere

End Function

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
how can I return a value in excel that looks at a range of number Help in Excel Excel Worksheet Functions 1 March 9th 06 08:27 PM
Return a specified date when it falls within a range.... Nokose451 Excel Discussion (Misc queries) 1 January 16th 06 10:06 PM
How to return a single value for a range of numbers Tami Excel Worksheet Functions 3 January 13th 06 02:34 AM
Vlookup return 0 when cell is blank Paul Excel Worksheet Functions 2 January 11th 06 05:01 PM
calculating return in a range kman Excel Worksheet Functions 5 December 27th 05 12:49 AM


All times are GMT +1. The time now is 06:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"