transpose data int listbox on userform based on two dates or without dates

Alaa mg

Active Member
Joined
May 29, 2021
Messages
343
Office Version
  1. 2019
Hello
I want merging amounts for each part item in column B for each sheet , when matching with column B for the each sheet . merging of the amounts should be for columns DEBIT or CREDIT and populate the names based on sheets names based on two condition . if the cells textbox1,textbox2are empty then will brings the names and merge amounts as pic1 in listbox1 and if there are two dates in textbox1,textbox2 then should brings the names and merging amounts within two dates as in pic2 .

every time add new sheets and new data or change data are already existed and also could be the others sheets are empty should ignore it until doesn't happen error.

ORIGINAL.xlsm
ABCDE
201/01/2023SALES INVOICE NN 8992,000.002,000.00
301/01/2023SALES INVOICE NN 9002,200.004,200.00
401/01/2023SALES INVOICE NN 9011,400.005,600.00
501/01/2023SALES INVOICE NN 9021,300.006,900.00
605/01/2023SALES INVOICE NN 9031,200.008,100.00
706/01/2023SALES INVOICE NN 9041,100.009,200.00
807/01/2023SALES INVOICE NN 9051,000.0010,200.00
908/01/2023SALES INVOICE NN 9061,500.0011,700.00
1009/01/2023SALES INVOICE NN 9071,600.0013,300.00
1110/01/2023SALES INVOICE NN 9081,800.0015,100.00
1211/01/2023CASH VOUCHER NO VM60005,000.0010,100.00
1312/01/2023SALES INVOICE NN 9096,000.0016,100.00
1412/01/2023CASH VOUCHER NO VM60017,000.009,100.00
1512/01/2023CASH VOUCHER NO VM60026,500.002,600.00
1612/01/2023CASH VOUCHER NO VM60031,200.001,400.00
1712/01/2023CASH VOUCHER NO VM6004230.001,170.00
1812/01/2023SALES INVOICE NN 9104,500.005,670.00
1912/01/2023CASH VOUCHER NO VM6005700.004,970.00
2012/01/2023CASH VOUCHER NO VM60061,000.003,970.00
2112/01/2023SALES INVOICE NN 9113,000.006,970.00
2212/01/2023SALES INVOICE NN 91260,000.0066,970.00
2312/01/2023PURCHASE INVOICE PP 90006,000.0060,970.00
2412/01/2023PURCHASE INVOICE PP 90015,000.0055,970.00
2512/01/2023PURCHASE INVOICE PP 90021,200.0054,770.00
2612/01/2023PAID VOUCHERVBG-8004,000.0058,770.00
2726/01/2023PAID VOUCHERVBG-8015,600.0064,370.00
2827/01/2023PURCHASE INVOICE PP 90035,600.0058,770.00
2928/01/2023PURCHASE INVOICE PP 90043,400.0055,370.00
3029/01/2023PURCHASE INVOICE PP 9005120.0055,250.00
3130/01/2023PURCHASE INVOICE PP 9006300.0054,950.00
3231/01/2023PURCHASE INVOICE PP 9007500.0054,450.00
3301/02/2023PURCHASE INVOICE PP 90083,400.0051,050.00
3402/02/2023PURCHASE INVOICE PP 90096,000.0045,050.00
3503/02/2023PURCHASE INVOICE PP 90107,000.0038,050.00
3604/02/2023PURCHASE INVOICE PP 90118,000.0030,050.00
3705/02/2023PURCHASE INVOICE PP 90129,000.0021,050.00
3806/02/2023PAID VOUCHERVBG-8025,000.0026,050.00
3907/02/2023PURCHASE INVOICE PP 90137,000.0019,050.00
4008/02/2023PURCHASE INVOICE PP 90145,000.0014,050.00
4109/02/2023PURCHASE INVOICE PP 90156,900.007,150.00
4210/02/2023PURCHASE INVOICE PP 90162,000.005,150.00
4311/02/2023PURCHASE INVOICE PP 90173,000.002,150.00
4412/02/2023SALES INVOICE NN 9135,000.007,150.00
4513/02/2023SALES INVOICE NN 9142,500.009,650.00
4614/02/2023SALES INVOICE NN 9156,000.0015,650.00
4715/02/2023SALES INVOICE NN 9162,000.0017,650.00
4816/02/2023SALES INVOICE NN 9171,200.0018,850.00
4917/02/2023SALES INVOICE NN 9183,000.0021,850.00
5018/02/2023SALES INVOICE NN 9194,000.0025,850.00
5119/02/2023SALES INVOICE NN 920500.0026,350.00
5220/02/2023SALES INVOICE NN 9216,000.0032,350.00
5321/02/2023SALES INVOICE NN 9227,000.0039,350.00
5422/02/2023SALES INVOICE NN 9238,000.0047,350.00
5523/02/2023SALES INVOICE NN 9249,000.0056,350.00
5624/02/2023SALES INVOICE NN 9253,000.0059,350.00
5725/02/2023SALES INVOICE NN 926490.0059,840.00
5826/02/2023PURCHASE INVOICE PP 90187,000.0052,840.00
5927/02/2023SALES INVOICE NN 927560.0053,400.00
6028/02/2023PAID VOUCHERVBG-803450.0053,850.00
6101/03/2023PAID VOUCHERVBG-804600.0054,450.00
6202/03/2023PAID VOUCHERVBG-805700.0055,150.00
6303/03/2023PAID VOUCHERVBG-806800.0055,950.00
6404/03/2023PAID VOUCHERVBG-807900.0056,850.00
6505/03/2023PURCHASE INVOICE PP 90196,000.0050,850.00
6606/03/2023PURCHASE INVOICE PP 9020700.0050,150.00
6707/03/2023PURCHASE INVOICE PP 9021800.0049,350.00
6808/03/2023PURCHASE INVOICE PP 90222,300.0047,050.00
6909/03/2023PURCHASE INVOICE PP 90231,200.0045,850.00
7010/03/2023PURCHASE INVOICE PP 90242,000.0043,850.00
7111/03/2023PURCHASE INVOICE PP 90251,234.0042,616.00
7212/03/2023PURCHASE INVOICE PP 90265,600.0037,016.00
7313/03/2023PURCHASE INVOICE PP 9027500.0036,516.00
7414/03/2023PURCHASE INVOICE PP 90282,400.0034,116.00
7515/03/2023PURCHASE INVOICE PP 90291,300.0032,816.00
7616/03/2023PURCHASE INVOICE PP 90307,000.0025,816.00
7717/03/2023PURCHASE INVOICE PP 9031500.0025,316.00
7818/03/2023PURCHASE INVOICE PP 9032600.0024,716.00
7919/03/2023PURCHASE INVOICE PP 9033600.0024,116.00
8020/03/2023PURCHASE INVOICE PP 9034700.0023,416.00
8121/03/2023PURCHASE INVOICE PP 9035800.0022,616.00
8222/03/2023PURCHASE INVOICE PP 90361,000.0021,616.00
8323/03/2023PURCHASE INVOICE PP 9037500.0021,116.00
8424/03/2023PURCHASE INVOICE PP 9038890.0020,226.00
8525/03/2023PURCHASE INVOICE PP 90394,500.0015,726.00
8626/03/2023PURCHASE INVOICE PP 90401,200.0014,526.00
8727/03/2023PURCHASE INVOICE PP 90411,000.0013,526.00
8828/03/2023PURCHASE INVOICE PP 9042500.0013,026.00
8929/03/2023PURCHASE INVOICE PP 90433,400.009,626.00
9030/03/2023PURCHASE INVOICE PP 9044600.009,026.00
9131/03/2023PURCHASE INVOICE PP 9045700.008,326.00
9201/04/2023PURCHASE INVOICE PP 9046230.008,096.00
9302/04/2023PURCHASE INVOICE PP 904790.008,006.00
9403/04/2023PURCHASE INVOICE PP 9048500.007,506.00
9504/04/2023PURCHASE INVOICE PP 9049700.006,806.00
9605/04/2023PURCHASE INVOICE PP 9050300.006,506.00
9706/04/2023PURCHASE INVOICE PP 9051690.005,816.00
9807/04/2023PURCHASE INVOICE PP 90521,200.004,616.00
9908/04/2023PURCHASE INVOICE PP 9053500.004,116.00
10009/04/2023PURCHASE INVOICE PP 90541,200.002,916.00
101TOTAL164,900.00161,984.002,916.00
ALAA
Cell Formulas
RangeFormula
E2,E101E2=C2-D2
E3:E100E3=E2+C3-D3
C101:D101C101=SUM(C2:C100)




ORIGINAL.xlsm
ABCDE
1DATEDESCRIPTIONDEBITCREDITBALANCE
201/01/2023SALES INVOICE NN 9277,000.007,000.00
301/01/2023SALES INVOICE NN 9286,000.0013,000.00
403/01/2023SALES INVOICE NN 9297,900.0020,900.00
504/01/2023SALES INVOICE NN 9308,000.0028,900.00
605/01/2023SALES INVOICE NN 93140,000.0068,900.00
706/01/2023CASH VOUCHER NO VM60074,000.0064,900.00
807/01/2023PURCHASE INVOICE PP 90556,000.0058,900.00
908/01/2023PURCHASE INVOICE PP 90567,000.0051,900.00
1009/01/2023PURCHASE INVOICE PP 90577,000.0044,900.00
1110/01/2023PURCHASE INVOICE PP 90588,000.0036,900.00
1211/01/2023PURCHASE INVOICE PP 90599,000.0027,900.00
1312/01/2023SALES INVOICE NN 9324,500.0032,400.00
1412/01/2023SALES INVOICE NN 9337,900.0040,300.00
1512/01/2023CASH VOUCHER NO VM60086,000.0034,300.00
1612/01/2023CASH VOUCHER NO VM60095,000.0029,300.00
1712/01/2023CASH VOUCHER NO VM60101,200.0028,100.00
1812/01/2023CASH VOUCHER NO VM60114,000.0024,100.00
1912/01/2023PAID VOUCHERVBG-8086,000.0030,100.00
2019/01/2023PAID VOUCHERVBG-8095,000.0035,100.00
2120/01/2023PAID VOUCHERVBG-8108,000.0043,100.00
2221/01/2023PAID VOUCHERVBG-8112,000.0045,100.00
2322/01/2023SALES INVOICE NN 9345,000.0050,100.00
2423/01/2023SALES INVOICE NN 9351,200.0051,300.00
2524/01/2023SALES INVOICE NN 936400.0051,700.00
2625/01/2023SALES INVOICE NN 937500.0052,200.00
2726/01/2023SALES INVOICE NN 938600.0052,800.00
2827/01/2023SALES INVOICE NN 939700.0053,500.00
2928/01/2023SALES INVOICE NN 9401,500.0055,000.00
3029/01/2023SALES INVOICE NN 9412,300.0057,300.00
3130/01/2023SALES INVOICE NN 9424,500.0061,800.00
3231/01/2023SALES INVOICE NN 9434,500.0066,300.00
3301/02/2023SALES INVOICE NN 944230.0066,530.00
3402/02/2023SALES INVOICE NN 9451,300.0067,830.00
3503/02/2023SALES INVOICE NN 946200.0068,030.00
3604/02/2023SALES INVOICE NN 947500.0068,530.00
3705/02/2023SALES INVOICE NN 9481,300.0069,830.00
3806/02/2023SALES INVOICE NN 94914,750.0084,580.00
3907/02/2023CASH VOUCHER NO VM60127,000.0077,580.00
4008/02/2023CASH VOUCHER NO VM60131,000.0076,580.00
4109/02/2023CASH VOUCHER NO VM60141,500.0075,080.00
4210/02/2023CASH VOUCHER NO VM60153,000.0072,080.00
4311/02/2023CASH VOUCHER NO VM60164,000.0068,080.00
4412/02/2023CASH VOUCHER NO VM60175,000.0063,080.00
4513/02/2023CASH VOUCHER NO VM60182,200.0060,880.00
4614/02/2023CASH VOUCHER NO VM60191,300.0059,580.00
4715/02/2023CASH VOUCHER NO VM6020500.0059,080.00
4816/02/2023CASH VOUCHER NO VM60213,500.0055,580.00
4917/02/2023SALES INVOICE NN 9505,600.0061,180.00
5018/02/2023CASH VOUCHER NO VM60227,000.0054,180.00
5119/02/2023CASH VOUCHER NO VM60235,000.0049,180.00
5220/02/2023CASH VOUCHER NO VM60242,200.0046,980.00
5321/02/2023CASH VOUCHER NO VM60251,300.0045,680.00
5422/02/2023PAID VOUCHERVBG-8127,000.0052,680.00
5523/02/2023PAID VOUCHERVBG-813600.0053,280.00
5624/02/2023PAID VOUCHERVBG-814500.0053,780.00
57TOTAL155,480.00101,700.0053,780.00
ALIAA
Cell Formulas
RangeFormula
E2,E57E2=C2-D2
E3:E56E3=E2+C3-D3
C57:D57C57=SUM(C2:C56)



ORIGINAL.xlsm
ABCDE
1DATEDESCRIPTIONDEBITCREDITBALANCE
201/01/2023SALES INVOICE NN 9514,000.004,000.00
302/01/2023SALES INVOICE NN 9529,000.0013,000.00
402/01/2023SALES INVOICE NN 9538,000.0021,000.00
502/01/2023SALES INVOICE NN 9548,000.0029,000.00
602/01/2023SALES INVOICE NN 95545,000.0074,000.00
702/01/2023SALES INVOICE NN 9561,200.0075,200.00
802/01/2023SALES INVOICE NN 9573,000.0078,200.00
902/01/2023SALES INVOICE NN 9582,000.0080,200.00
1002/01/2023SALES INVOICE NN 9591,500.0081,700.00
1110/01/2023SALES INVOICE NN 9601,300.0083,000.00
1211/01/2023SALES INVOICE NN 9611,400.0084,400.00
1312/01/2023SALES INVOICE NN 9625,000.0089,400.00
1412/01/2023SALES INVOICE NN 9333,000.0092,400.00
1512/01/2023CASH VOUCHER NO VM60256,000.0086,400.00
1612/01/2023SALES INVOICE NN 9347,000.0093,400.00
1712/01/2023CASH VOUCHER NO VM60269,000.0084,400.00
1812/01/2023CASH VOUCHER NO VM602710,000.0074,400.00
1912/01/2023CASH VOUCHER NO VM602812,000.0062,400.00
2012/01/2023CASH VOUCHER NO VM602914,000.0048,400.00
2112/01/2023PAID VOUCHERVBG-8154,000.0052,400.00
2212/01/2023PAID VOUCHERVBG-8165,000.0057,400.00
2322/01/2023PAID VOUCHERVBG-81712,000.0069,400.00
2423/01/2023PAID VOUCHERVBG-8181,200.0070,600.00
2524/01/2023PAID VOUCHERVBG-819120.0070,720.00
2625/01/2023PAID VOUCHERVBG-820450.0071,170.00
2726/01/2023SALES INVOICE NN 938600.0071,770.00
2827/01/2023SALES INVOICE NN 9391,200.0072,970.00
2928/01/2023SALES INVOICE NN 9401,300.0074,270.00
3029/01/2023SALES INVOICE NN 9413,000.0077,270.00
3130/01/2023SALES INVOICE NN 9424,000.0081,270.00
3231/01/2023SALES INVOICE NN 9432,000.0083,270.00
3301/02/2023SALES INVOICE NN 9442,200.0085,470.00
3402/02/2023SALES INVOICE NN 945120.0085,590.00
3503/02/2023SALES INVOICE NN 9461,500.0087,090.00
3604/02/2023SALES INVOICE NN 947300.0087,390.00
3705/02/2023SALES INVOICE NN 9481,200.0088,590.00
3806/02/2023SALES INVOICE NN 9491,000.0089,590.00
3907/02/2023CASH VOUCHER NO VM60127,800.0081,790.00
4008/02/2023CASH VOUCHER NO VM60131,300.0080,490.00
4109/02/2023CASH VOUCHER NO VM60141,200.0079,290.00
4210/02/2023CASH VOUCHER NO VM60151,000.0078,290.00
4311/02/2023CASH VOUCHER NO VM60161,700.0076,590.00
4412/02/2023CASH VOUCHER NO VM60171,800.0074,790.00
4513/02/2023CASH VOUCHER NO VM60188,000.0066,790.00
4614/02/2023CASH VOUCHER NO VM60199,000.0057,790.00
4715/02/2023CASH VOUCHER NO VM60208,700.0049,090.00
4816/02/2023CASH VOUCHER NO VM60211,200.0047,890.00
4917/02/2023SALES INVOICE NN 9504,000.0051,890.00
5018/02/2023CASH VOUCHER NO VM6022100.0051,790.00
5119/02/2023CASH VOUCHER NO VM6023200.0051,590.00
5220/02/2023CASH VOUCHER NO VM6024300.0051,290.00
5321/02/2023CASH VOUCHER NO VM6025400.0050,890.00
5422/02/2023PAID VOUCHERVBG-8121,200.0052,090.00
5523/02/2023PAID VOUCHERVBG-813500.0052,590.00
5624/02/2023PAID VOUCHERVBG-814550.0053,140.00
5725/02/2023PAID VOUCHERVBG-81515,000.0068,140.00
5826/02/2023CASH VOUCHER NO VM602640,000.0028,140.00
5927/02/2023CASH VOUCHER NO VM602715,000.0013,140.00
60TOTAL161,840.0093,700.0068,140.00
ALOAA
Cell Formulas
RangeFormula
E2,E60E2=C2-D2
E3:E59E3=E2+C3-D3
C60C60=SUM(C2:C59)
D60D60=SUM(D2:D56)


first case when textbox1,textbox2 are empty
1W.PNG



second case when there are two dates
W2.PNG

at leas data for each sheet could be 4000 rows and could reach 12 sheets
any suggestion to make the things easy I'm in all ears.
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December
Hi @Alaa mg

Do the following:
1. Add a commandbutton to your form.
2. Run the form.
3. Capture the 2 dates or delete the 2 dates.
4. Press the button.
5. Adjust on this line the concepts that must be added.
arr = Array("NAME", "SALES INVOICE", "PURCHASE INVOICE", "CASH VOUCHER", "PAID VOUCHER")​
6. The code only considers the sheets that have the text "DATE" in cell A1.

Considerations:
- The code validates that you capture both dates or none.
- At the beginning of the form the process may be slow, because it is loading all the information in arrays.
- But once the information is loaded, the filters will be faster.

Put all of the following code in your form:
VBA Code:
Option Explicit
  Dim b As Variant, c As Variant
  Dim arr As Variant
  Dim di1 As Object, di2 As Object

Private Sub CommandButton1_Click()
  Dim tb1 As String, tb2 As String
  Dim i As Long, j As Long, m As Long, nRow As Long, nCol As Long
  Dim d As Variant
  
  tb1 = TextBox1.Value
  tb2 = TextBox2.Value
  If tb1 = "" And tb2 <> "" Then
     MsgBox "Missing date"
     TextBox1.SetFocus
     Exit Sub
  End If
  If tb1 <> "" And tb2 = "" Then
     MsgBox "Missing date"
     TextBox2.SetFocus
     Exit Sub
  End If
  If tb1 <> "" Then
    If Not IsDate(tb1) Then
      MsgBox "Enter valid date"
      TextBox1.SetFocus
      Exit Sub
    End If
  End If
  If tb2 <> "" Then
    If Not IsDate(tb2) Then
      MsgBox "Enter valid date"
      TextBox2.SetFocus
      Exit Sub
    End If
  End If
  
  If tb1 = "" And tb2 = "" Then
    ListBox1.List = c
  Else
    ReDim d(1 To UBound(c, 1), 1 To UBound(c, 2))
    For i = 1 To UBound(c, 1)
      d(i, 1) = c(i, 1)
    Next
    For m = 2 To UBound(c, 2)
      d(1, m) = c(1, m)
    Next
    
    For i = 1 To UBound(b, 1)
      If b(i, 1) >= CDate(tb1) And b(i, 1) <= CDate(tb2) Then
        nRow = di1(b(i, 2))
        nCol = di2(b(i, 6))
        d(nRow, nCol) = d(nRow, nCol) + b(i, 3) + b(i, 4)
      End If
    Next
    
    For i = 2 To UBound(c, 1)
      For j = 2 To UBound(c, 2)
        If d(i, j) = "" Then d(i, j) = 0
        d(i, j) = Format(d(i, j), "#,##0.00")
      Next
    Next
    ListBox1.List = d
  End If
End Sub

Private Sub UserForm_Activate()
  Dim sh As Worksheet
  Dim a() As Variant
  Dim i As Long, j As Long, k As Long, lr As Long, m As Long, n As Long
  Dim nRow As Long, nCol As Long
  
  arr = Array("NAME", "SALES INVOICE", "PURCHASE INVOICE", "CASH VOUCHER", "PAID VOUCHER")
  Set di1 = CreateObject("Scripting.Dictionary")
  Set di2 = CreateObject("Scripting.Dictionary")
  
  For Each sh In Sheets
    If sh.Range("A1").Value = "DATE" Then
      n = n + 1
      di2(sh.Name) = n + 1
      lr = lr + sh.Range("B" & Rows.Count).End(3).Row - 1
    End If
  Next
  ReDim b(1 To lr, 1 To 6)                      'data for all sheets
  ReDim c(1 To UBound(arr, 1) + 1, 1 To n + 1)  'sum of all dates
  For m = 0 To UBound(arr)
    c(m + 1, 1) = arr(m)
    di1(arr(m)) = m + 1
  Next
  
  n = 1
  For Each sh In Sheets
    Erase a
    If sh.Range("A1").Value = "DATE" Then
      n = n + 1
      c(1, n) = sh.Name
      a = sh.Range("A2:E" & sh.Range("B" & Rows.Count).End(3).Row).Value2
      For i = 1 To UBound(a, 1)
        k = k + 1
        For j = 1 To UBound(a, 2)
          If j = 2 Then
            For m = 1 To UBound(arr)
              If Left(a(i, 2), Len(arr(m))) = arr(m) Then
                b(k, j) = arr(m)
                Exit For
              End If
            Next
          Else
            b(k, j) = a(i, j)
          End If
        Next
        b(k, UBound(b, 2)) = sh.Name
      Next
    End If
  Next
  
  For i = 1 To UBound(b, 1)
    nRow = di1(b(i, 2))
    nCol = di2(b(i, 6))
    c(nRow, nCol) = c(nRow, nCol) + b(i, 3) + b(i, 4)
  Next
  
  For i = 2 To UBound(c, 1)
    For j = 2 To UBound(c, 2)
      If c(i, j) = "" Then c(i, j) = 0
      c(i, j) = Format(c(i, j), "#,##0.00")
    Next
  Next
  
  With ListBox1
    .ColumnCount = n
    .List = c
  End With
End Sub

Comment on your test results with all the sheets and all the data.
Cordially
Dante Amor
:)
 
Last edited:
Upvote 0
Solution
6. The code only considers the sheets that have the text "DATE" in cell A1.
sorry about first picture doesn't copy header in row 1 when I posted the thread !🙏
I'm really grateful for your assistance .👍
thank you so much :)
 
Upvote 0

Forum statistics

Threads
1,215,069
Messages
6,122,959
Members
449,096
Latest member
Anshu121

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