["vba"] Sum 3 days of work per person

montecarlo2012

Well-known Member
Joined
Jan 26, 2011
Messages
986
Office Version
  1. 2010
Platform
  1. Windows
Hi,
I am trying to figure out how to coding a total sales by person, I just upload 3 days info.
what I have now and where :
1599445437628.png

as you see for example Derek total per day, I would like the same for the rest.
I can think about the pseudocode (maybe) like this
VBA Code:
start

On I3:I10 if B2:B33 names match H3:H10 then
Sum(offset , c,d,e,)

On J3:J10 if B2:B33 names match H3:H10 then
Sum(offset , c,d,e,)

On k3:k10 if B2:B33 names match H3:H10 then
Sum(offset , c,d,e,)

End
what I was reading in different website is more or less how to use sum and offset, but honestly I didn't figure out, so here I am. Please give a hand here.
Thanks
 

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.
Here an example, with Formulas!

Mappe1
ABCDEFGHI
1workersday1day2day3workersday1day2day3
2derek527derek71012
3derek285jane7210
4jane7210john253760
5john6715kim10409
6john9519peter286
7john41021terri12813
8john6155tim25138
9kim2192tom40810
10kim8217
11peter286
12terri729
13terri564
14tim1096
15tim1542
16tom1968
17tom2122
Ark1
Cell Formulas
RangeFormula
G2:I9G2=SUMPRODUCT(($A$2:$A$17=$F2)*(($B$1:$D$1=G$1))*B$2:B$17)
Press CTRL+SHIFT+ENTER to enter array formulas.
 
Upvote 0
Or using a non array formula
+Fluff New.xlsm
ABCDEFGHI
1workersday1day2day3workersday1day2day3
2derek527derek71012
3derek285jane7210
4jane7210john253760
5john6715kim10409
6john9519peter286
7john41021terri12813
8john6155tim25138
9kim2192tom40810
10kim8217
11peter286
12terri729
13terri564
14tim1096
15tim1542
16tom1968
17tom2122
18
Master
Cell Formulas
RangeFormula
G2:I9G2=SUMIFS(B:B,$A:$A,$F2)
 
Upvote 0
Or with VBA
VBA Code:
Sub montecarlo()
   Dim Ary As Variant, Nary As Variant
   Dim r As Long, nr As Long, rr As Long, c As Long
   
   Ary = Sheets("Sheet1").Range("A1").CurrentRegion.Value2
   ReDim Nary(1 To UBound(Ary), 1 To UBound(Ary, 2))
   With CreateObject("Scripting.dictionary")
      For r = 2 To UBound(Ary)
         If Not .Exists(Ary(r, 1)) Then
            nr = nr + 1
            .Add Ary(r, 1), nr
            Nary(nr, 1) = Ary(r, 1)
         End If
         rr = .Item(Ary(r, 1))
         For c = 2 To UBound(Ary, 2)
            Nary(rr, c) = Nary(rr, c) + Ary(r, c)
         Next c
      Next r
   End With
   Sheets("Sheet1").Cells(2, c + 1).Resize(nr, UBound(Ary, 2)).Value = Nary
End Sub
 
Upvote 0
Ebea, thank you so much, specially you took the time to re-write my data and upload on xl2BB, awesome, sorry but I tried to download the application 2BB but I got a lot problem after.
anyway, thanks again.
 
Upvote 0
Fluff, thank you so much. Is a really pretty code, I understand you work with the info provided by ebea
thats why the answer is on F and not on H like the first images,
so I move my data to column A and delete the answers I have before,
and I am working now on figuring out how can I change locations to any where.

I found only one place they talk about scripting dictionary,
but not to the level you show here, is a really complex code.

what I can see is there are two for next loops, one for rows [for r = ] and one for columns [for c =]
Ary is for the code to read the sheet, Redim is reading the array,

.Add Ary(r, 1), nr , Nary(nr, 1) = Ary(r, 1) here I get lost

I assume if this line is out -- > With CreateObject("Scripting.dictionary")
and then the code will be longer (maybe?)
I don't know, is really beautiful and awesome code Mr. Fluff

Thank you again for your GREAT work.
 
Upvote 0
Your welcome ;-) Regarding Xl2BB it should be straight forward. The only problem I have experienced, is that I have to reactivate the Plug In, under "File", and "settings".
 
Upvote 0
ebea, You did awesome job, and really appreciate your time, thank you
in my case I download the app but my computer start some kind of weird behave like virus or malware
then I delete the app, and everything come back to normal.
I hope to see you arround
 
Upvote 0
Glad to help & thanks for the feedback.
 
Upvote 0
ebea, You did awesome job, and really appreciate your time, thank you
in my case I download the app but my computer start some kind of weird behave like virus or malware
then I delete the app, and everything come back to normal.
I hope to see you arround
Your welcome! Check your Computer, for malware, and then retry with the XL2BB ;-)
 
Upvote 0

Forum statistics

Threads
1,223,910
Messages
6,175,320
Members
452,635
Latest member
laura12345

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