According to your attachment a variation of the same way you already have in your previous threads as a beginner starter
to paste only to the Sheet3 (Consolidate) worksheet class module :
PHP Code:
Sub Demo1() Dim L&, oDic As Object, S&, V, R& L = 1 UsedRange.Clear Set oDic = CreateObject("Scripting.Dictionary"): oDic.CompareMode = 1 Application.ScreenUpdating = False With CreateObject("Scripting.Dictionary") .CompareMode = 1 For S = Sheets("BR1 Cat").Index To Index - 1 V = Sheets(S).[A1].CurrentRegion Cells(L, 1).Resize(UBound(V), 3) = V L = L + UBound(V) For R = 1 To UBound(V) .Item(V(R, 1)) = .Item(V(R, 1)) + V(R, 2) oDic(V(R, 3)) = oDic(V(R, 3)) + V(R, 2) Next R, S [A1].CurrentRegion.RemoveDuplicates 1 [B1].Resize(.Count) = Application.Transpose(.Items) .RemoveAll End With [I1:J1].Resize(oDic.Count) = Application.Transpose(Array(oDic.Keys, oDic.Items)) Application.ScreenUpdating = True oDic.RemoveAll: Set oDic = Nothing End Sub
► Do you like it ? ► ► So thanks to click on bottom left star icon « ★ Add Reputation » ! ◄ ◄
You felt into the bad reader trap ‼ So just delete the useless Module1 and
as plain text explained in post #2 paste the VBA demonstration where it must be : into the worksheet module
All your mods are useless - one is even wrong ! - if you just well read and follow the post #2 dark red direction
And according to VBA help - a must read, at kid level ! - you are wrong as there is obviously not any missng Next statement
or my VBA demonstration can't work so I never would post it !
I have a another example to copy data from sheets F and I BR1 to the last sheet by copying the data in Cols A to J up to the last row containing data in Col A on these sheets and to combine the data and paste into sheet "Consolidated"
I have tried to amend the orignal code, but cannot get the code to work
I have Data in Cols A:J on sheets BR1 F and I Data to the last sheet
I need to combine the values In Col E where the descriptions In Col B are the same as well as combining the values in Col J where the descriptions in Col I are the same and paste these in the same cols as on these sheets on sheet consolidated
I have manually added the values to show the result on workbook "Consolidated Sales Manual Calc.xlsm"
Kindly test and provide me with code to combine the values
According to your post #15 attachment an Excel / VBA basics demonstration to paste to the Sheet3 (Consolidate) worksheet module :
PHP Code:
Sub Demo2() Dim S&, R&, V, T#(), L& UsedRange.Clear With Application .ScreenUpdating = False For S = 2 To Sheets.Count With Sheets(S).UsedRange .Columns("A:B").Copy Cells(R + 1, 1) R = R + .Rows.Count End With Next Range("A1:B" & R).RemoveDuplicates 1 V = [A1].CurrentRegion.Columns(1) ReDim T(1 To UBound(V), 0) With New Collection For R = 1 To UBound(V): .Add R, CStr(V(R, 1)): Next For S = 2 To Sheets.Count For R = 1 To Sheets(S).UsedRange.Rows.Count L = .Item(Sheets(S).Cells(R, 1).Text) T(L, 0) = T(L, 0) + Sheets(S).Cells(R, 5) Next R, S End With [E1].Resize(UBound(T)) = T [I1:J1] = Array(Sheets(2).[I1], .Sum(T)) .ScreenUpdating = True End With End Sub
► Do you like it ? ► ► So thanks to click on bottom left star icon « ★ Add Reputation » ! ◄ ◄
Thanks for the help -Beyond Excel. Your code is perfect.
Please explain significance of code below:
With pleasure:
a) The data is collected in a recordset: Rst
b) The recordset has 3 fields: F1, F2 and F3 with the following characteristics:
F1: Long
F2:String
F3:Double
c) The part of the VBA code that you show is the way to define such fields.
d) This has not been the case, but before downloading the data to the sheet using the ".CopyFromRecordset" method, an ordering could be done by any of the 3 fields, for example.
Maybe yes, maybe no : no clue as - again - it depends on the exact layout and the exact expected result !
Proceeding like you do just means you have the Excel / VBA skills to fit yourself any code any helper can share
but when it's not the case, that's just a non sense, a waste of time
Bookmarks