Sumifs VBA with multiple criteria in multiple cells

xs4amit

New Member
Joined
May 21, 2018
Messages
34
Hi Excel Champs,

Please help me getting this calculated

I have data like this

DateEmp CodeEmp NameProductivityAHT
15-02-2018726462ABC25410 Min
15-02-2018734840DEF12312 Min
15-02-2018746569GHI6563 Min
15-02-2018726462ABC15320 Min
15-02-2018734840DEF3456 Min
15-02-2018746569GHI23410 Min
15-02-2018726462ABC4845 Min
15-02-2018734840DEF5562 Min
16-02-2018726462ABC64512 Min
16-02-2018746569GHI9372 Min
16-02-2018734840DEF29410 Min
16-02-2018734840DEF4755 Min
16-02-2018746569GHI28410 Min

<tbody>
</tbody>

And data goes on for upcoming dates in next Rows.


Where i need to make a productivity report out of above data like this

Emp CodeEmp Name15-02-201816-02-201817-02-201818-02-2018
726462ABC=SUMIFS()=SUMIFS()
734840DEF

<tbody>
</tbody>

Right now i am using SUMIFS but my data expands upto 50000 Rows and SUMIFS is very slow. Can you please help me with a VBA code which calculates this for above table.
 
There must be a more elegant way to do this. That said, this code assumes your data is in Sheet1 starting in cell A1. It will write your results to Sheet2 starting in Cell A1..

Code:
Sub EmpSum()
   
    Dim ws1 As Worksheet: Set ws1 = Worksheets("Sheet1")
    Dim ws2 As Worksheet: Set ws2 = Worksheets("Sheet2")
    Dim lRow As Long, x As Long, lRow2 As Long, i As Long, c As Long
    Dim dts As Variant
   
    lRow = ws1.Cells(Rows.Count, 1).End(xlUp).Row
    dts = ws1.Range("A2:A" & lRow)


    With CreateObject("Scripting.Dictionary")
        For x = LBound(dts) To UBound(dts)
            If Not IsMissing(dts(x, 1)) Then .Item(dts(x, 1)) = 1
        Next
        dts = .Keys
    End With
   
    ws2.Range("C1").Resize(, UBound(dts) + 1) = dts
    ws1.Range("B1:C" & lRow).Copy ws2.Range("A1")
    ws2.Range("A2:B" & lRow).RemoveDuplicates Columns:=Array(1, 2), _
        Header:=xlNo
    lRow2 = ws2.Cells(Rows.Count, 1).End(xlUp).Row
   
    For c = 3 To 3 + UBound(dts)
        For i = 2 To lRow2
            ws2.Cells(i, c) = Application.WorksheetFunction.SumIfs _
            (ws1.Range("D:D"), ws1.Range("A:A"), ws2.Cells(1, c), _
            ws1.Range("B:B"), ws2.Range("A" & i))
        Next
    Next
   
End Sub
Hello igold! Your code helped me out with very difficult task I have to solve. But I have one issue with pasted dates - sometimes when change query in SQL which give me the dates on sheet1 and get this pasted to sheet2 the dates are not in ascending order after pasting, sometimes are. Can you help with this to ensure that the dates are always in correct order? Thank you in advance!
 
Upvote 0

Excel Facts

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.
Hi kuldar, welcome to the MrExcel forum.

In the future it is preferred, and more advantageous if you start a new thread with your question and not tack on to the bottom of an existing thread.

Without seeing any data, the first question I would ask is- can you sort the data before moving it...
 
Upvote 0
Hi kuldar, welcome to the MrExcel forum.

In the future it is preferred, and more advantageous if you start a new thread with your question and not tack on to the bottom of an existing thread.

Without seeing any data, the first question I would ask is- can you sort the data before moving it...
It is not very smart idea to continue the same topic in another thread but keep discussion related to topic together.

All data was posted, I can not sort array before moving. Sorting array 'dts' is necessary because I want to order article numbers ascending as well as dates.
 
Upvote 0
Ok, how about an example of some data. You may want to use XL2BB. Similar to what the OP of this thread did.
 
Upvote 0

Forum statistics

Threads
1,214,990
Messages
6,122,625
Members
449,093
Latest member
catterz66

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top