Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Urgent - SumIf being stubborn!

Status
Not open for further replies.

Wolfen02

Technical User
Mar 8, 2004
22
0
0
US
I'm using the following formula in VBA to try to get the number of symbols in Range2 where Range1 is null. There are 5 possible symbols to be found in either range. The formula will only return zero. Where am I going wrong?!?

s = Application.WorksheetFunction.SumIf(Range1, "=" """",Range2)

Teri
Good decisions come from Wisdom...
Wisdom comes from experience...
Experience comes from bad decisions
 
SumIf(Range1, "="" """,Range2)


Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
PHV,
Formula still only returns zero. Thanks for the try though.


Teri
Good decisions come from Wisdom...
Wisdom comes from experience...
Experience comes from bad decisions
 
Solved my issue by looping along the If statements. Slower, but works!

Teri
Good decisions come from Wisdom...
Wisdom comes from experience...
Experience comes from bad decisions
 
How about:-

Hardwired Range
Code:
Sub SumPr1()
    Dim wks As Worksheet
    Set wks = Worksheets("sheet1")
    
    With wks
      myval = Evaluate("SUMPRODUCT((" _
              & .Range("A1:A30").Address(external:=True) & "="""") *(" _
              & .Range("B1:B30").Address(external:=True) & "<>""""" _
              & "))")
    End With
    
    MsgBox myval
    
End Sub

or
Code:
Sub SumPr2()
    Dim wks As Worksheet
    Dim rng1 As Range
    Dim rng2 As Range
        
    Set wks = Worksheets("sheet1")
    
    With wks
      Set rng1 = .Range("A1:A30")
      Set rng2 = .Range("B1:B30")
    
      myval = Evaluate("SUMPRODUCT((" _
              & rng1.Address(external:=True) & "="""") *(" _
              & rng2.Address(external:=True) & "<>""""" _
              & "))")
    End With
    
    MsgBox myval
    
End Sub

Regards
Ken.................

----------------------------------------------------------------------------
[peace]It's easier to beg forgiveness than ask permission[2thumbsup]

----------------------------------------------------------------------------
 
The following function adds up the values in range2 in rows where range1 is blank.
Code:
Function mySumIF(range1 As Range, range2 As Range)
mySumIF = Application.SumIf(range1, "=" & "", range2)
End Function
Note that it is comparing the values in range1 to
 
Hi byundt - I think you can even lose the '"=" &' bit can't you:-

Code:
Function mySumIF(range1 As Range, range2 As Range)
    mySumIF = Application.SumIf(range1, "", range2)
End Function

Problem is though that I think the OP is looking to count disparate symbols, and if he has 5 of them then any summation of values (if indeed they are even values) will likely not be able to get a valid count for him.

Regards
Ken..............

----------------------------------------------------------------------------
[peace]It's easier to beg forgiveness than ask permission[2thumbsup]

----------------------------------------------------------------------------
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top