macro to match partial item in list across sheet and populate amounts.

Abdo

Board Regular
Joined
May 16, 2022
Messages
201
Office Version
  1. 2019
  2. 2010
Platform
  1. Windows
Hi experts,
maybe this way see some members is strange or not logic about calculation , but I need this way .
my idea will match partial item in list in SUMMARY sheet with the same partial item across sheets , if the same partial of the item is existed in columns DEBIT , CREDIT . first of all will merge amount for DEBIT or CREDIT column in the same sheet , second should sum DEBIT,CREDIT columns together
example : in summary sheet will match PUR PURCHASE across sheets .
in CSMN PURCHASE will be after sum DEBIT=112,800 and in CSMT PURCHASE sheet will be after sum CREDIT =66000 so the final result as show in summary sheet will be = 112800+66000=178800 and so on for the others items also I will add new sheets before summary sheet with the same structure and the same idea .
every time I will add new items in column B for summary sheet .
REF.xlsm
ABCD
1DATEACCOUNT REFDEBITCREDIT
201/05/2023PUR PURCHASE INV 00001120,000.00
302/05/2023PUR PURCHASE INV 00001220,000.00
403/05/2023PUR PURCHASE INV 00001320,000.00
504/05/2023PUR PURCHASE INV 00001420,000.00
605/05/2023PUR PURCHASE INV 00001520,000.00
706/05/2023PA PAYING 7891,000.00
807/05/2023PA PAYING 7901,000.00
908/05/2023PUR PURCHASE INV 0000162,000.00
1009/05/2023PUR PURCHASE INV 0000171,200.00
1110/05/2023PUR PURCHASE INV 0000181,300.00
1211/05/2023PUR PURCHASE INV 0000191,400.00
1312/05/2023PUR PURCHASE INV 0000201,000.00
1413/05/2023PUR PURCHASE INV 0000211,200.00
1514/05/2023PUR PURCHASE INV 0000221,200.00
1615/05/2023PUR PURCHASE INV 0000231,200.00
1716/05/2023PUR PURCHASE INV 0000241,300.00
1817/05/2023PUR PURCHASE INV 0000251,000.00
CSMN PURCHASE



REF.xlsm
ABCD
1DATEACCOUNT REFDEBITCREDIT
201/05/2023PUR PURCHASE INV 00001112,000.00
302/05/2023PUR PURCHASE INV 00001123,000.00
403/05/2023PUR PURCHASE INV 00001134,000.00
504/05/2023PUR PURCHASE INV 00001145,000.00
605/05/2023PUR PURCHASE INV 00001156,000.00
706/05/2023PUR PURCHASE INV 00001167,000.00
807/05/2023PUR PURCHASE INV 00001178,000.00
908/05/2023PUR PURCHASE INV 00001189,000.00
1009/05/2023PA PAYING 791300.00
1110/05/2023PA PAYING 792400.00
1211/05/2023PA PAYING 793500.00
1312/05/2023PA PAYING 794340.00
1413/05/2023PUR PURCHASE INV 00001193,000.00
1514/05/2023PUR PURCHASE INV 00001204,000.00
1615/05/2023PUR PURCHASE INV 00001215,000.00
1716/05/2023PUR PURCHASE INV 00001226,000.00
1817/05/2023PUR PURCHASE INV 00001234,000.00
CSMT PURCHASE


REF.xlsm
ABCD
1DATEACCOUNT REFDEBITCREDIT
201/05/2023VC VOUCHER PAY 100011,200.00
302/05/2023VC VOUCHER PAY 100021,800.00
403/05/2023VC VOUCHER PAY 100031,200.00
504/05/2023VC VOUCHER PAY 100041,300.00
605/05/2023VC VOUCHER PAY 100051,400.00
706/05/2023VC VOUCHER PAY 100061,500.00
807/05/2023VC VOUCHER PAY 100071,700.00
908/05/2023VC VOUCHER PAY 10008
1009/05/2023VC VOUCHER RECEIVED 100092,000.00
1110/05/2023VC VOUCHER RECEIVED 100103,000.00
1211/05/2023VC VOUCHER PAY 10011600.00
1312/05/2023VC VOUCHER PAY 10012700.00
1413/05/2023VC VOUCHER PAY 10013600.00
CSMN CASH



REF.xlsm
ABCD
1DATEACCOUNT REFDEBITCREDIT
201/06/2023VC VOUCHER RECEIVED V 10002,000.00
302/06/2023VC VOUCHER RECEIVED V 10013,000.00
403/06/2023VC VOUCHER RECEIVED V 10024,000.00
504/06/2023VC VOUCHER RECEIVED V 10033,000.00
605/06/2023VC VOUCHER PAY 100142,000.00
706/06/2023VC VOUCHER PAY 100153,000.00
807/06/2023VC VOUCHER PAY 100161,200.00
908/06/2023VC VOUCHER PAY 100171,000.00
1009/06/2023VC VOUCHER PAY 100181,200.00
1110/06/2023VC VOUCHER PAY 100191,300.00
1211/06/2023VC VOUCHER RECEIVED V 1004200.00
1312/06/2023VC VOUCHER RECEIVED V 1005225.00
1413/06/2023VC VOUCHER RECEIVED V 1006300.00
1514/06/2023VC VOUCHER RECEIVED V 1007400.00
1615/06/2023VC VOUCHER RECEIVED V 1008500.00
1716/06/2023VC VOUCHER RECEIVED V 1009600.00
1817/06/2023VC VOUCHER RECEIVED V 1010700.00
SRTRYUH CASH




REF.xlsm
ABCD
1DATEACCOUNT REFDEBITCREDIT
201/06/2023SAL SALES SR00014,000.00
302/06/2023SAL SALES SR00028,000.00
403/06/2023SAL SALES SR00033,000.00
504/06/2023SAL SALES SR00042,000.00
605/06/2023SAL SALES SR00051,000.00
706/06/2023SAL SALES SR00061,200.00
807/06/2023SAL SALES SR00075,000.00
908/06/2023RE SALES SR00082,000.00
1009/06/2023RE SALES SR00091,200.00
1110/06/2023RE SALES SR00101,300.00
1211/06/2023SAL SALES SR000114,000.00
1312/06/2023SAL SALES SR000121,200.00
1413/06/2023SAL SALES SR000132,000.00
1514/06/2023SAL SALES SR000142,000.00
1615/06/2023SAL SALES SR000152,000.00
1716/06/2023SAL SALES SR000162,000.00
1817/06/2023SAL SALES SR000172,000.00
SRTRYUH SR SALE



REF.xlsm
ABC
1ITEMACCOUNT REFBALANCE
21PUR PURCHASE
32PA PAYING
43VC VOUCHER PAY
54VC VOUCHER RECEIVED
65SAL SALES
76RE SALES
87
98
109
1110
1211
1312
1413
1514
1615
1716
18CALCULATION
summary




OUTPUT should be
REF.xlsm
ABC
1ITEMACCOUNT REFBALANCE
21PUR PURCHASE178,800.00
32PA PAYING3,540.00
43VC VOUCHER PAY21,700.00
54VC VOUCHER RECEIVED19,925.00
65SAL SALES39,400.00
76RE SALES4,500.00
87
98
109
1110
1211
1312
1413
1514
1615
1716
18CALCULATION
summary

thanks
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
You could achieve your objective with some simple sumif formulas. Using the sample you posted at Excel Forum: Populate amounts for separated range based on matching headers across sheets for partial for demonstration purposes:

REF1.xlsm
BC
1ACCOUNT REF
2PUR PURCHASE
3ITEMCREDIT
41178,800.00
5TOTAL178,800.00
summary
Cell Formulas
RangeFormula
C4C4=(SUMIF('CSMN PURCHASE'!B:B,C2&"*",'CSMN PURCHASE'!D:D)+SUMIF('CSMT PURCHASE'!B:B,C2&"*",'CSMT PURCHASE'!D:D))-(SUMIF('CSMN PURCHASE'!B:B,C2&"*",'CSMN PURCHASE'!C:C)+SUMIF('CSMT PURCHASE'!B:B,C2&"*",'CSMT PURCHASE'!C:C))
C5C5=C4
 
Upvote 0
you misread ,two threads and different requests.

in other forum there is separated ranges and will link separated range each of other .

in here I want the list will link in another list and another sheet.

so why answer Q in other forum and Q here is different?!!

two both threads I have different goals , I don't have to explain the whole and real my project, just I ask part of my request .
by the way I ask here macro because I have big data , just I gave sample .
 
Upvote 0
OK, using your XL2BB posts on this thread, I still wouldn't be using macros when simple formulas will give you the same result. It doesn't matter how big the data is, the formulas reference entire columns. Just reference the relevant sheets within the formulas.
If you're set on doing this via VBA, I'll leave it to someone else.

Book1
ABC
1ITEMACCOUNT REFBALANCE
21PUR PURCHASE178,800.00
32PA PAYING3,540.00
43VC VOUCHER PAY21,700.00
54VC VOUCHER RECEIVED19,925.00
65SAL SALES39,400.00
76RE SALES4,500.00
87
98
109
1110
1211
1312
1413
1514
1615
1716
18CALCULATION
summary
Cell Formulas
RangeFormula
C2:C3C2=(SUMIF('CSMN PURCHASE'!B:B,B2&"*",'CSMN PURCHASE'!D:D)+SUMIF('CSMT PURCHASE'!B:B,B2&"*",'CSMT PURCHASE'!D:D))+(SUMIF('CSMN PURCHASE'!B:B,B2&"*",'CSMN PURCHASE'!C:C)+SUMIF('CSMT PURCHASE'!B:B,B2&"*",'CSMT PURCHASE'!C:C))
C4:C5C4=(SUMIF('CSMN CASH'!B:B,B4&"*",'CSMN CASH'!D:D)+SUMIF('SRTRYUH CASH'!B:B,B4&"*",'SRTRYUH CASH'!D:D))+(SUMIF('CSMN CASH'!B:B,B4&"*",'CSMN CASH'!C:C)+SUMIF('SRTRYUH CASH'!B:B,B4&"*",'SRTRYUH CASH'!C:C))
C6:C7C6=(SUMIF('SRTRTYUH SR SALE'!B:B,B6&"*",'SRTRTYUH SR SALE'!C:C)+SUMIF('SRTRTYUH SR SALE'!B:B,B6&"*",'SRTRTYUH SR SALE'!D:D))
 
Upvote 0
It doesn't matter how big the data is, the formulas reference entire columns
but could effect when search for entire column and most of cells are empty .

theses formulas need modifying every time when add new sheets before summary sheet as I said
also I will add new sheets before summary sheet with the same structure and the same idea .
that's why I want vba
ok you can't help with vba even if that thank you.
 
Upvote 0
by the way there is problem in your last formula it will open dialog to select file and select sheet and then will shows error #value!.
 
Upvote 0
@Abdo
Try:
VBA Code:
Sub abdo_1()
Dim i As Long, j As Long, n As Long
Dim c As Range
Dim va, vb, vs, wsn, ary

ary = Split("CSMN PURCHASE/CSMT PURCHASE/CSMN CASH/SRTRYUH CASH/SRTRYUH SR SALE", "/")
Sheets("Summary").Activate

va = Range("B2", Cells(Rows.Count, "B").End(xlUp))
ReDim vs(1 To UBound(va), 1 To 1)

For i = 1 To UBound(va, 1)
    For Each wsn In ary
        With Sheets(wsn)
        Set c = .Range("B:B").Find(What:=x, LookIn:=xlValues, lookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
        If Not c Is Nothing Then
                n = .Range("B" & Rows.Count).End(xlUp).Row
                
                vb = .Range("B2:B" & n).Resize(, 3)
                
                For j = 1 To UBound(vb, 1)
                    If InStr(1, vb(j, 1), va(i, 1), vbTextCompare) > 0 Then
                    
                        vs(i, 1) = vs(i, 1) + vb(j, 2) + vb(j, 3)
                        'Debug.Print vb(j, 1) & " : " & i & " : " & vs(i, 1)
                    End If
                Next
        End If
        End With
    
    Next

Next

Range("C2").Resize(UBound(vs, 1), 1) = vs
End Sub

but I got different result in C2:C3, not sure why:
abdo - macro to match partial item `.xlsm
ABC
1ITEMACCOUNT REFBALANCE
21PUR PURCHASE132000
32PA PAYING3080
43VC VOUCHER PAY21700
54VC VOUCHER RECEIVED19925
65SAL SALES39400
76RE SALES4500
87
98
109
1110
1211
1312
1413
1514
1615
1716
18CALCULATION
Summary


you can uncomment this line:
VBA Code:
'Debug.Print vb(j, 1) & " : " & i & " : " & vs(i, 1)
to see each iteration result in Immediate Window.
 
Upvote 1
@Akuini
well done !(y)
but I got different result in C2:C3, not sure why:
really strange!:rolleyes:
I have got the same result as in OP.
REF.xlsm
ABC
1ITEMACCOUNT REFBALANCE
21PUR PURCHASE178,800.00
32PA PAYING3,540.00
43VC VOUCHER PAY21,700.00
54VC VOUCHER RECEIVED19,925.00
65SAL SALES39,400.00
76RE SALES4,500.00
87
98
109
1110
1211
1312
1413
1514
1615
1716
18CALCULATION
summary

I have a question about array for sheets in this line
VBA Code:
ary = Split("CSMN PURCHASE/CSMT PURCHASE/CSMN CASH/SRTRYUH CASH/SRTRYUH SR SALE", "/")
is there better way than specify sheets names ?
as I said will add new sheets before summary sheet , then if I'm not wrong will I have to write new sheets in array line every time add new sheet.
thank you for your time .
 
Upvote 0
is there better way than specify sheets names ?
as I said will add new sheets before summary sheet , then if I'm not wrong will I have to write new sheets in array line every time add new sheet.

Do you mean you want to execute the code in all sheets except sheet Summary?
Try:
VBA Code:
Sub abdo_2()
Dim i As Long, j As Long, n As Long
Dim c As Range
Dim va, vb, vs
Dim wsn As Worksheet


Sheets("Summary").Activate

va = Range("B2", Cells(Rows.Count, "B").End(xlUp))
ReDim vs(1 To UBound(va), 1 To 1)

For i = 1 To UBound(va, 1)
    For Each wsn In Worksheets
        If wsn.Name <> "Summary" Then
            With wsn
            Set c = .Range("B:B").Find(What:=x, LookIn:=xlValues, lookAt:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)
                If Not c Is Nothing Then
                        n = .Range("B" & Rows.Count).End(xlUp).Row
                        
                        vb = .Range("B2:B" & n).Resize(, 3)
                        
                        For j = 1 To UBound(vb, 1)
                            If InStr(1, vb(j, 1), va(i, 1), vbTextCompare) > 0 Then
                            
                                vs(i, 1) = vs(i, 1) + vb(j, 2) + vb(j, 3)
                                'Debug.Print vb(j, 1) & " : " & i & " : " & vs(i, 1)
                            End If
                        Next
                End If
            End With
        End If
    
    Next

Next

Range("C2").Resize(UBound(vs, 1), 1) = vs
End Sub

really strange!:rolleyes:
I have got the same result as in OP
I probably copy-paste wrong data.
 
Upvote 0
Solution
yes , Akuini this is what I want it.
thank you so much for your help .
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,853
Members
452,361
Latest member
d3ad3y3

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