Results 1 to 10 of 10

Convert Sumifs to vba code with loop

Threaded View

  1. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,834

    Re: Convert Sumifs to vba code with loop

    You have prepared col G & H, Criteria 1 & 2.
    Do you want to keep it remain as it is, or is it fine just the data that have month=N1?

    This is to output the only data that have Month = N1
    to a Sheet Module
    Private Sub Worksheet_Change(ByVal Target As Range)
        If Target.Address(0, 0) <> "N1" Then Exit Sub
        Application.EnableEvents = False
        test
        Application.EnableEvents = True
    End Sub
    To a standard module
    Sub test()
        Dim a, i As Long, ii As Long, w, txt As String, myMonth As Long
        myMonth = [n1].Value
        a = Cells(1).CurrentRegion.Resize(, 4).Value
        With CreateObject("Scripting.Dictionary")
            .CompareMode = 1
            For i = 2 To UBound(a, 1)
                If a(i, 3) = myMonth Then
                    txt = Join(Array(a(i, 1), a(i, 2)), Chr(2))
                    If Not .exists(txt) Then
                        ReDim w(1 To 3)
                        For ii = 1 To 2
                            w(ii) = a(i, ii)
                        Next
                    Else
                        w = .Item(txt)
                    End If
                    w(3) = w(3) + a(i, 4)
                    .Item(txt) = w
                End If
            Next
            a = Empty
            If .Count Then a = Application.Index(.items, 0, 0)
        End With
        [g1:h1].CurrentRegion.Offset(1).ClearContents
        [k1].CurrentRegion.Offset(1).ClearContents
        If IsArray(a) Then
            [g2:h2].Resize(UBound(a, 1)).Value = a
            [k2].Resize(UBound(a, 1)).Value = Application.Index(a, 0, 3)
        End If
    End Sub
    Attached Files Attached Files
    Last edited by jindon; 11-11-2015 at 07:43 PM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. [SOLVED] Convert SUMIFS formula to SUMPRODUCT
    By timbury1 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 11-08-2014, 01:18 PM
  2. VBA Sumifs Loop
    By SimonJF in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-08-2013, 12:18 AM
  3. Loop function SUMIFS
    By jnh0 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 09-05-2013, 12:35 PM
  4. convert sumifs to run it on excel 2003
    By albert28 in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 08-01-2013, 06:30 AM
  5. [SOLVED] convert sumifs
    By rana_shaker in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-02-2012, 12:15 PM
  6. [SOLVED] Use TEXT function as Criteria on Sumifs to convert month/year to date format
    By chico.corrales in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 11-08-2012, 07:49 PM
  7. Convert SUMIFS formula for 2003
    By SAsplin in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 12-30-2009, 07:40 AM

Tags for this Thread

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