+ Reply to Thread
Results 1 to 10 of 10

sumif in VBA

Hybrid View

  1. #1
    Registered User
    Join Date
    06-21-2016
    Location
    Brazil
    MS-Off Ver
    2002
    Posts
    23

    sumif in VBA

    Need a little help with a simple sumif. I dont know why it keeps telling me the Sumif formula has a sintaxe error.

     Range("G & rw").Value = Application.WorksheetFunction.SumIfs(range("N:N"),Range("C & rw),Range("S:S")
    It sais it expected a text separator were i input colum S:S.

    This looks like a very simple problem, but i couldnt find anything alike here in the forum, and i cant solve it.



    Sub Macro1()
    Dim LR As Integer
    Dim rw As Integer
    
    LR = Range("C" & Rows.Count).End(xlUp).Row
        
        For rw = 2 To LR
    
            If Not IsEmpty(Range("C" & rw).Value) Then
    
        Range("G & rw").Value = Application.WorksheetFunction.SumIfs(range("N:N"),Range("C & rw),Range("S:S")
    
            End If
    
            If Range("G" & rw).Value = 0 Then
                Range("G" & rw).Value = "-"
                Range("F" & rw).Value = "N緌"
            ElseIf Range("G" & rw).Value <> 0 Then
                Range("F" & rw).Value = "Sim"
            End With
     
        Next rw
    End Sub

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,983

    Re: sumif in VBA

    On the right side you are missing a close quote and a close paren, and the left side the quote is in the wrong place:

     Range("G" & rw).Value = Application.WorksheetFunction.SumIfs(range("N:N"),Range("C" & rw),Range("S:S"))
    Last edited by 6StringJazzer; 07-04-2016 at 08:49 AM. Reason: Kept finding more code errors after the original post
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    06-21-2016
    Location
    Brazil
    MS-Off Ver
    2002
    Posts
    23

    Re: sumif in VBA

    I fixted it, but it is giving me error '438' - object doesn't support this property or method

  4. #4
    Registered User
    Join Date
    06-21-2016
    Location
    Brazil
    MS-Off Ver
    2002
    Posts
    23

    Re: sumif in VBA

    haha i knew it was just something stupid. Thank you

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,983

    Re: sumif in VBA

    I found a couple more errors after my original post and edited my response. You may have copied my response before I made those changes. Are you using the latest version? Please try again.

    If it still doesn't work, show exactly what you are using and give the value of rw when the error occurs.

  6. #6
    Registered User
    Join Date
    06-21-2016
    Location
    Brazil
    MS-Off Ver
    2002
    Posts
    23

    Re: sumif in VBA

    I forgot to mention i use excel 2002. But I would guess this function is available to this version anyways.

    i've tryed a few things, and it keeps sending the same msg.

    Sub Macro1()
    Dim LR As Integer
    Dim rw As Integer
    Dim RSum As Integer
    
    LR = Range("C" & Rows.Count).End(xlUp).Row
    RSum = Range("n" & Rows.Count).End(xlUp).Row
    
        For rw = 2 To LR
    
            If Not IsEmpty(Range("C" & rw).Value) Then
    
            'Range("G & rw").Formula = "=somase(("N2:N60"),("C"&rw), ("S2:S"&RSum))
    
    
            
            Range("G" & rw).Value = Application.WorksheetFunction.SumIfs(Range("N2:N" & RSum), Range("C" & rw), Range("S2:S" & RSum))
    
            End If
    
            If Range("G" & rw).Value = 0 Then
                Range("G" & rw).Value = "-"
                Range("F" & rw).Value = "N緌"
            ElseIf Range("G" & rw).Value <> 0 Then
                Range("F" & rw).Value = "Sim"
            
            End If
        Next rw
    End Sub

  7. #7
    Forum Guru bakerman2's Avatar
    Join Date
    10-03-2012
    Location
    Antwerp, Belgium
    MS-Off Ver
    MSO Home and Business 2024
    Posts
    7,344

    Re: sumif in VBA

    I forgot to mention i use excel 2002. But I would guess this function is available to this version anyways.
    Simple answer. NOPE

    You will have to turn to SumProduct.
    Avoid using Select, Selection and Activate in your code. Use With ... End With instead.
    You can show your appreciation for those that have helped you by clicking the * at the bottom left of any of their posts.

  8. #8
    Registered User
    Join Date
    06-21-2016
    Location
    Brazil
    MS-Off Ver
    2002
    Posts
    23

    Re: sumif in VBA

    So excel 2002 does not suport sumif in VBA? I can do the sumif funtion in the normal excel, it only gives me this messege while i try to insert the function in visual basic mode. Then if this is the case, how could I get this done with other formulas?

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS 365 Family 64-bit 2502
    Posts
    26,983

    Re: sumif in VBA

    Sorry, didn't realize that was not available in 2002. I have not used VBA in any version prior to 2003.

    SUMIFS was introduced in Excel 2007. You are only using one criterion so you could use SUMIF (you must change the syntax to match). If SUMIF is not available in your version of Excel, this is how you could use SUMPRODUCT:
    Application.WorksheetFunction.SUMPRODUCT(Range("N2:N" & RSum) * --(Range("C" & rw) = Range("S2:S" & RSum)))
    I can't test this properly without your file but give it a try.

  10. #10
    Registered User
    Join Date
    06-21-2016
    Location
    Brazil
    MS-Off Ver
    2002
    Posts
    23

    Re: sumif in VBA

    GOT IT! its not 'sumifs'... its just 'sumif'

    thank you!

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. SumIf formula or Sumif with pivottable combined question
    By mcgleeuw in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-10-2015, 01:05 PM
  2. Replies: 4
    Last Post: 12-04-2014, 02:06 PM
  3. Subtracting from the SUMIF with the difference from the SUMIF range
    By iamblue91 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 09-04-2014, 09:01 PM
  4. [SOLVED] sumif i know , sumif with fix cell i dont know
    By makinmomb in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 05-05-2014, 04:22 PM
  5. [SOLVED] Shorten SUMIF + SUMIF + SUMIF each with same reference range but different criteria???
    By HeyInKy in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 04-13-2014, 09:25 PM
  6. SUMIF or SUMIF's formula with multiple criteria
    By jackiemariee in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-30-2013, 06:19 PM
  7. Nested SUMIF statement or multiple SUMIF's
    By Dan27 in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 09-17-2009, 06:55 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1