Summing values based on matching column across sheets
Solved/Closed
leapout
Posts
20
Registration date
Monday 1 March 2021
Status
Member
Last seen
26 April 2022
-
12 Apr 2022 à 12:08
leapout Posts 20 Registration date Monday 1 March 2021 Status Member Last seen 26 April 2022 - 26 Apr 2022 à 16:36
leapout Posts 20 Registration date Monday 1 March 2021 Status Member Last seen 26 April 2022 - 26 Apr 2022 à 16:36
Related:
- Summing values based on matching column across sheets
- Google sheets download - Download - Spreadsheets
- Based on the values in cells b77 ✓ - Excel Forum
- Based on the values in cells b77 b81 c77 - Excel Forum
- Name Values - Excel Forum
- Excel column number - Guide
2 responses
TrowaD
Posts
2921
Registration date
Sunday 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
19 Apr 2022 à 11:32
19 Apr 2022 à 11:32
Hi Leapout,
Could you check if the code below yields the desired result:
Best regards,
Trowa
Could you check if the code below yields the desired result:
Sub RunMe()
Dim mWS1, mWS2, mWS3 As Worksheet
Dim mRow, x, lRow As Long
Dim mFind As Range
Set mWS1 = Sheets("Sheet1")
Set mWS2 = Sheets("Sheet2")
Set mWS3 = Sheets("Summary")
x = 2
mWS1.Select
lRow = Range("B1").End(xlDown).Row
nSheet:
For mRow = x To lRow
Set mFind = mWS3.Columns("B").Find(Cells(mRow, "B").Value)
mWS3.Cells(mFind.Row, Columns.Count).End(xlToLeft).Offset(0, -2).Value = Cells(mRow, "F").Value
mWS3.Cells(mFind.Row, Columns.Count).End(xlToLeft).Offset(0, -1).Value = Cells(mRow, "G").Value
If mRow = lRow And ActiveSheet.Name = mWS1.Name Then
mWS2.Select
lRow = Range("B1").End(xlDown).Row
GoTo nSheet
End If
Next mRow
End Sub
Best regards,
Trowa
TrowaD
Posts
2921
Registration date
Sunday 12 September 2010
Status
Contributor
Last seen
27 December 2022
555
26 Apr 2022 à 12:11
26 Apr 2022 à 12:11
Hi Leapout,
Sure thing. The last BUYING and SELLING columns will be cleared, before the new values will be placed.
Here is the code (also with both adjustments from post 3):
Best regards,
Trowa
Sure thing. The last BUYING and SELLING columns will be cleared, before the new values will be placed.
Here is the code (also with both adjustments from post 3):
Sub RunMe()
Dim mWS1, mWS2, mWS3 As Worksheet
Dim mRow, x, lRow, lCol As Long
Dim mFind As Range
Set mWS1 = Sheets("Sheet1")
Set mWS2 = Sheets("Sheet2")
Set mWS3 = Sheets("Summary")
x = 2
lCol = mWS3.Cells(1, Columns.Count).End(xlToLeft).Column
Range(mWS3.Cells(2, lCol - 2), mWS3.Cells(Rows.Count, lCol - 1)).ClearContents
mWS1.Select
lRow = Range("B1").End(xlDown).Row
nSheet:
For mRow = x To lRow
Set mFind = mWS3.Columns("B").Find(Cells(mRow, "B").Value)
mWS3.Cells(mFind.Row, lCol).Offset(0, -2).Value = mWS3.Cells(mFind.Row, lCol).Offset(0, -2).Value + Cells(mRow, "F").Value
mWS3.Cells(mFind.Row, lCol).Offset(0, -1).Value = mWS3.Cells(mFind.Row, lCol).Offset(0, -1).Value + Cells(mRow, "G").Value
If mRow = lRow And ActiveSheet.Name = mWS1.Name Then
mWS2.Select
lRow = Range("B1").End(xlDown).Row
GoTo nSheet
End If
Next mRow
mWS3.Select
End Sub
Best regards,
Trowa
leapout
Posts
20
Registration date
Monday 1 March 2021
Status
Member
Last seen
26 April 2022
1
Updated on Apr 26, 2022 at 04:37 PM
Updated on Apr 26, 2022 at 04:37 PM
Hi TrowaD,
excellent ! thanks for your time & solution .
Best regards,
Leapout
excellent ! thanks for your time & solution .
Best regards,
Leapout
Updated on Apr 19, 2022 at 05:02 PM
thanks for this code , but I have one thing ,
sometimes there are duplicates items for sheet1,2 then should sum the values when show in sheet summary
I'm talking about column BUYING between sheet1,2
best regards,
Leapout
25 Apr 2022 à 11:58
Code line 16 determines the 'Buying' column value. To add to this value instead of replacing, then change that line:
into:
If you want to do the same with the 'Selling' column, then change code line 17:
into:
Best regards,
Trowa
26 Apr 2022 à 06:06
Great ! just last thing , I would replace data when run the macro repeatedly for the same columns BUYING & SELLING because I notice if I run the macro more than one time accidentally for the same columns BUYING & SELLING it continues to sum the values over previous value repeatedly . I don't want it . this makes getting the values are wrong based on the others sheets .
thanks