Merge data on userform for each sheet based on multiple columns.

Maklil

Board Regular
Joined
Jun 23, 2022
Messages
193
Office Version
  1. 2019
Platform
  1. Windows
Hi Guys,
I expect data could reach for about 12000 rows for each sheet.
so I would show this report on userform as in picture when there are no dates in TB1,TB2.


mkl.PNG



mk.xlsm
ABCDEFGHI
1DATEINV NONAMEIDCASESAFESQTYUNIT PRICEBALANCE
220/08/2023MMUY7000MVSOOIL AS-100PAIDASDFT SAFE20.00160.003,200.00
320/08/2023MMUY7000MVSOOIL AS-101PAIDASDFT SAFE20.00180.003,600.00
4TOTAL6,800.00
520/08/2023MMUY7001MVSOOIL AS-102PAIDASDFT SAFE40.00155.006,200.00
620/08/2023MMUY7001MVSOOIL AS-103PAIDASDFT SAFE20.00190.003,800.00
7TOTAL10,000.00
821/08/2023MMUY7002MVSOOIL AS-103NOT PAID25.00190.004,750.00
9TOTAL4,750.00
1021/08/2023MSSOOIL AS-103NOT PAID25.00180.004,500.00
1121/08/2023MSSOOIL AS-104NOT PAID40.00177.007,080.00
12TOTALOOIL AS-10511,580.00
1321/08/2023MMUY7002MVSOOIL AS-103PAIDYOUSEF SAFE100.00196.0019,600.00
14TOTAL19,600.00
MK
Cell Formulas
RangeFormula
I13,I10:I11,I8,I5:I6,I2:I3I2=G2*H2
I4,I12,I7I4=SUM(I2:I3)
I9,I14I9=SUM(I8)





mk.xlsm
ABCDEFGHI
1DATEINV NONAMEIDCASESAFESQTYUNIT PRICEBALANCE
220/08/2023ST NO 1000MVSGNOO HH 1200RECEIVEDYOUSEF SAFE10.00150.001,500.00
320/08/2023ST NO 1000MVSAS100-12RECEIVEDYOUSEF SAFE10.00130.001,300.00
4TOTAL2,800.00
521/08/2023ST NO 1001MTTMGFH GA-103NOT REICEVED15.00130.001,950.00
6TOTAL1,950.00
721/08/2023ST NO 1002MLLSSFOO 1000 MN1NOT REICEVED2.00140.00280.00
821/08/2023ST NO 1002MLLSSFOO 1000 MN2NOT REICEVED12.00145.001,740.00
921/08/2023ST NO 1002MLLSSFOO 1000 MN3NOT REICEVED10.00145.001,450.00
10TOTAL3,470.00
1124/08/2023VT NO 1003MKKOOIL AS-100RECEIVEDYOUSEF SAFE10.00145.001,450.00
1224/08/2023VT NO 1003MKKOOIL AS-101RECEIVEDYOUSEF SAFE25.00150.003,750.00
1324/08/2023VT NO 1003MKKOOIL AS-102RECEIVEDYOUSEF SAFE40.00155.006,200.00
1424/08/2023VT NO 1003MKKOOIL AS-103RECEIVEDYOUSEF SAFE55.00160.008,800.00
1524/08/2023VT NO 1003MKKOOIL AS-104RECEIVEDYOUSEF SAFE70.00165.0011,550.00
1624/08/2023VT NO 1003MKKOOIL AS-105RECEIVEDYOUSEF SAFE85.00170.0014,450.00
1724/08/2023VT NO 1003MKKOOIL AS-106RECEIVEDYOUSEF SAFE100.00175.0017,500.00
1824/08/2023VT NO 1003MKKOOIL AS-107RECEIVEDYOUSEF SAFE115.00180.0020,700.00
19TOTAL84,400.00
2024/08/2023ST NO 1002MLLSSFOO 1000 MN11NOT REICEVED12.00160.001,920.00
2124/08/2023ST NO 1002MLLSSFOO 1000 MN21NOT REICEVED12.00170.002,040.00
22TOTAL3,960.00
MT
Cell Formulas
RangeFormula
I11:I18,I5,I2:I3I2=G2*H2
I4,I22I4=SUM(I2:I3)
I6I6=SUM(I5:I5)
I20:I21,I7:I9I7=H7*G7
I10I10=SUM(I7:I9)
I19I19=SUM(I11:I18)




mk.xlsm
ABCDEFGHI
1DATEINV NONAMEIDCASESAFESQTYUNIT PRICEBALANCE
220/08/2023MSSUY4000MVSOOIL AS-100RECEIVEDAFORI BANK1.00160.00160.00
320/08/2023MSSUY4000MVSOOIL AS-101RECEIVEDAFORI BANK1.00180.00180.00
4TOTAL340.00
520/08/2023MSSUY4001MVSOOIL AS-102NOT REICEVED1.00155.00155.00
620/08/2023MSSUY4001MVSOOIL AS-103NOT REICEVED1.00190.00190.00
7TOTAL345.00
821/08/2023MSSUY4002MVSOOIL AS-102RECEIVEDAMTOR BANK2.00155.00310.00
9TOTAL310.00
1021/08/2023MSSUY4003MSSOOIL AS-100NOT REICEVED1.00160.00160.00
1121/08/2023MSSUY4003MSSOOIL AS-101NOT REICEVED1.00180.00180.00
1221/08/2023MSSUY4003MSSOOIL AS-102NOT REICEVED1.00155.00155.00
13TOTAL495.00
MS
Cell Formulas
RangeFormula
I10:I12,I8,I5:I6,I2:I3I2=G2*H2
I4,I7I4=SUM(I2:I3)
I9I9=SUM(I8)
I13I13=SUM(I10:I12)





mk.xlsm
ABCDEFGHI
1DATEINV NONAMEIDCASESAFESQTYUNIT PRICEBALANCE
224/08/2023VT NO 1003MKKOOIL AS-100NOT PAID1.00145.00145.00
324/08/2023VT NO 1003MKKOOIL AS-101NOT PAID1.00150.00150.00
424/08/2023VT NO 1003MKKOOIL AS-102NOT PAID2.00155.00310.00
524/08/2023VT NO 1003MKKOOIL AS-103NOT PAID4.00160.00640.00
6TOTAL1,245.00
725/08/2023VT NO 1004MKKOOIL AS-101PAIDYOUSEF SAFE1.00150.00150.00
825/08/2023VT NO 1004MKKOOIL AS-102PAIDYOUSEF SAFE2.00155.00310.00
9TOTAL460.00
1025/08/2023VT NO 1005MLLOOIL AS-103PAIDASTORI BANK4.00160.00640.00
11TOTAL640.00
1225/08/2023VT NO 1006MLLOOIL AS-102PAIDYOUSEF SAFE2.00155.00310.00
1325/08/2023VT NO 1006MLLOOIL AS-103PAIDYOUSEF SAFE4.00160.00640.00
14TOTAL950.00
1525/08/2023VT NO 1007MKKOOIL AS-101PAIDASTORI BANK3.00150.00450.00
16TOTAL450.00
ATS
Cell Formulas
RangeFormula
I15,I12:I13,I10,I7:I8,I2:I5I2=G2*H2
I6I6=SUM(I2:I5)
I9,I14I9=SUM(I7:I8)
I11,I16I11=SUM(I10)




mk.xlsm
ABCDEF
1DATEVOUCHER NONAMECASESAFESTOTAL
220/08/2023VDD1000MVSPAIDASDFT SAFE200
321/08/2023VDD1001MVSPAIDASDFT SAFE120
422/08/2023VDD1002MKKRECEIVEDYOUSEF SAFE100
523/08/2023VDD1003MVSRECEIVEDYOUSEF SAFE120
623/08/2023VDD1004MKKPAIDAFORI BANK120
724/08/2023VDD1005MKKPAIDYOUSEF SAFE100
825/08/2023VDD1006MVSPAIDAFORI BANK200
925/08/2023VDD1007MVSPAIDYOUSEF SAFE100
1025/08/2023VDD1008MKKRECEIVEDAFORI BANK120
VFTY


1- in column(2) in listbox will show sheets names
2- in column(3) in listbox will show items under SAFES column across sheets.
3- column(4) in listbox will brings amount is existed in TOTAL row for column|(I) for each sheet and merge amounts for duplicates items in SAFES column , CASE column together for each sheet alone.
4- and should show zero as hyphen for each digit in columns don't contain amount .
5- as to amounts for NOTPAID,NOT RECEIVED don't contain item in SAFES column then should show for first row for each sheet.
6- should sreach within two dates in TB1,TB2
by the way I have got solution by Dante amore like really similar project but unfortunately I have to change some things .😣
thanks .
 
Which sheets are you referring to here 'then should show for first row for each sheet.'?
I meant when there is repeated sheets name so should put amount for the first time shows then should show amounts in the same row for first showing for each sheet as show in the picture
for instance MK sheet repeated twice then 16,330.00 will show in first time when doesn't contain item in SAFES column as marked .
jk.JPG


Please post an XL2BB mini-sheet.
I'm not sure how show by form !
I mean having combo boxes to select the date range instead of having to type the dates into the text boxes.
if it's possible by textboxes will be great , if not then I accept by comboboxes.
 
Upvote 0

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest
Code:
Option Explicit

Private Sub CommandButton1_Click()
    Dim myList, i&, x$, s(1 To 2)
    Me.ListBox1.Clear
    For i = 1 To 2
        x = Me("textbox" & i)
        If x <> "" Then
            If Not x Like "##/##/####" Then
                MsgBox "Date should be dd/mm/yyyy format" & vbLf & "e.g. 31/01/2025": Exit Sub
            Else
                s(i) = GetSerialDate(x)
            End If
        End If
    Next
    myList = GetList(s)
    With Me.ListBox1
        .ColumnCount = UBound(myList, 2)
        .TextAlign = 2
        If UBound(myList, 2) > 1 Then .Column = myList
    End With
End Sub

Function GetSerialDate&(s$)
    Dim x
    x = Split(s, "/")
    GetSerialDate = DateSerial(x(2), x(1), x(0))
End Function

Function GetList(d)
    Dim a, b, e, i&, ii&, n&, dic As Object
    Dim key, s, cols, col, ws, x, maxDate&, temp#
    Set dic = CreateObject("Scripting.Dictionary")
    ws = Array("MK", "MT", "MS", "ATS", "VFTY")
    ReDim tbl(UBound(ws)) As Range
    For i = 0 To UBound(tbl)
        Set tbl(i) = Sheets(ws(i)).[a1].CurrentRegion
        maxDate = Application.Max(maxDate, tbl(i).Columns(1))
    Next
    If d(2) = 0 Then d(2) = maxDate
    cols = Array("PAID", "NOT PAID", "RECEIVED", "NOT REICEVED")
    ReDim a(1 To 7, 1 To 1): n = 1
    a(1, 1) = "ITEM": a(2, 1) = "SHEET NAMES": a(3, 1) = "SAFES"
    For i = 0 To UBound(cols)
        a(i + 4, 1) = cols(i)
    Next
    For Each e In tbl
        key = Application.Match("SAFES", e.Rows(1), 0)
        s = Application.Match("CASE", e.Rows(1), 0)
        b = e.Value2: dic.RemoveAll: temp = 0
        For i = 2 To UBound(b)
            If b(i, s) <> "" Then
                If (b(i, 1) >= d(1)) * (b(i, 1) <= d(2)) Then
                    If b(i, key) = "" Then If dic.Count Then b(i, key) = dic.keys()(0)
                    If b(i, key) <> "" Then
                        If Not dic.exists(b(i, key)) Then
                            n = n + 1: dic(b(i, key)) = n
                            ReDim Preserve a(1 To 7, 1 To n): a(1, n) = n - 1
                            a(2, n) = e.Parent.Name: a(3, n) = b(i, key)
                        End If
                    End If
                    x = Application.Match(b(i, s), cols, 0)
                    If b(i, s) Like "NOT *" Then
                        col = x
                        temp = temp + b(i, UBound(b, 2))
                    Else
                        a(x + 3, dic(b(i, key))) = _
                        Format$(Val(Replace(a(x + 3, dic(b(i, key))), ",", "")) + b(i, UBound(b, 2)), "#,0.00")
                    End If
                End If
            End If
        Next
        If dic.Count Then
            If col Then a(col + 3, dic.items()(0)) = temp
            For i = dic.items()(0) To dic.items()(dic.Count - 1)
                For ii = 4 To 7
                    If (a(ii, i) = "") + (a(ii, i) = 0) Then a(ii, i) = "-"
                Next
            Next
        End If
    Next
    GetList = a
End Function
 
Upvote 0
Solution
@Fuji
this is really awesome!
I notice your code doesn't show format number in NOT PAID, NOT RECEIVED columns, may also show ,please?
also I don't know how add ColumnWidths to your code to adjustment spaces among columns in listbox, may you guide me please?
 
Upvote 0
1)
Rich (BB code):
        If dic.Count Then
            If col Then a(col + 3, dic.items()(0)) = temp
Rich (BB code):
        If dic.Count Then
            If col Then a(col + 3, dic.items()(0)) = Format$(temp, "#,0.00")
2)
Code:
    With Me.ListBox1
        .ColumnCount = UBound(myList, 2)
        .TextAlign = 2
        If UBound(myList, 2) > 1 Then .Column = myList
    End With
Rich (BB code):
    With Me.ListBox1
        .ColumnCount = UBound(myList, 2)
        .ColumnWidths = ";;;;;;"
        .TextAlign = 2
        If UBound(myList, 2) > 1 Then .Column = myList
    End With
 
Upvote 0

Forum statistics

Threads
1,225,897
Messages
6,187,703
Members
453,435
Latest member
U4US

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