sort higlighted data into listbox on userform

Mussa

Active Member
Joined
Jul 12, 2021
Messages
264
Office Version
  1. 2019
  2. 2010
hello

I need helping to adapt my project . what I want when run the userform should just show highlighted data by yellow also when writing item into textbox1 based on column 4 into list box should show data based on textbox1 .
so when run userform or search item into textbox1 should just depends on higlighted data as in sheet


البحث بالتيكست بوكس معتمدة على بيانات بالليست بوكس.xlsm
ABCDEFGHIJ
1DATE CLIENT NOINVOICE NOID-CCBB-RTT-YOR-GGQTYPRICETOTAL
205/01/2021CC2-TRB-1INV-TRGG-1IDTR-100FFDOOD-1PACK-2TTR60.00$120.00$7,200.00
306/01/2021CC2-TRB-1INV-TRGG-1IDTR-101FFDOOD-2PACK-3BBR10.00$130.00$1,300.00
407/01/2021CC2-TRB-1INV-TRGG-1IDTR-102FFDOOD-3PACK-4LLR5.00$100.00$500.00
508/01/2021CC2-TRB-1INV-TRGG-1IDTR-103FFDOOD-4PACK-5MMR10.00$289.00$2,890.00
609/01/2021CC2-TRB-2INV-TRGG-2IDTR-104FFDOOD-5PACK-6ASDR5.00$140.00$700.00
710/01/2021CC2-TRB-2INV-TRGG-2IDTR-100FFDOOD-1PACK-2TTR30.00$100.00$3,000.00
811/01/2021CC2-TRB-2INV-TRGG-2IDTR-101FFDOOD-2PACK-3BBR50.00$120.00$6,000.00
912/01/2021CC2-TRB-2INV-TRGG-2IDTR-107FFDOOD-6PACK-7FFG12.00$200.00$2,400.00
1013/01/2021CC2-TRB-2INV-TRGG-2IDTR-108FFDOOD-7PACK-8GGF13.00$100.00$1,300.00
PURCHASE
Cell Formulas
RangeFormula
J2:J10J2=H2*I2




this is userform




the whole code
VBA Code:
Option Explicit

Dim a As Variant

Private Sub TextBox1_Change()
  Call FilterData
End Sub

Private Sub TextBox2_Change()
  Call FilterData
End Sub

Private Sub TextBox3_Change()
  Call FilterData
End Sub

Sub FilterData()
    Dim i As Long, ii As Long, n As Long
    Me.ListBox1.List = a
    If Me.TextBox1 = "" Then Exit Sub
    With Me.ListBox1
        .Clear
        For i = 0 To UBound(a, 1)
            If UCase$(a(i, 3)) Like UCase$(Me.TextBox1) & "*" Then
                .AddItem
                .List(n, 0) = n + 1
                For ii = 1 To UBound(a, 2)
                    .List(n, ii) = a(i, ii)
                Next
                n = n + 1
            End If
        Next
    End With
End Sub

Private Sub UserForm_Activate()

      

End Sub
Private Sub UserForm_Initialize()
    Dim lindex&
    Dim rngDB As Range, rng As Range
    Dim i, myFormat(1) As String
    Dim sWidth As String
    Dim vR() As Variant
    Dim n As Integer
    Dim myMax As Single
    Set rngDB = Range("A2:J20")
    For Each rng In rngDB
        n = n + 1
        ReDim Preserve vR(1 To n)
        vR(n) = rng.EntireColumn.Width
    Next rng
    myMax = WorksheetFunction.Max(vR)
    For i = 1 To n
        vR(i) = myMax
    Next i
    With Sheets("purchase").Cells(1).CurrentRegion
        myFormat(0) = .Cells(2, 8).NumberFormatLocal
        myFormat(1) = .Cells(2, 9).NumberFormatLocal
        Set rng = .Offset(1).Resize(.Rows.Count - 1)
        a = .Cells(1).CurrentRegion.Value
    End With

    sWidth = Join(vR, ";")
    Debug.Print sWidth
    With ListBox1
        .ColumnCount = 10
        .ColumnWidths = sWidth '<~~ 63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63;63
        .List = rng.Value
        .BorderStyle = fmBorderStyleSingle
        For lindex = 0 To .ListCount - 1
            '.List(lindex, 0) = (Format((.List(lindex, 0)), "dd/mm/yyyy"))   ' BL = dates
                        .List(lindex, 0) = lindex + 1

            .List(lindex, 7) = Format$(.List(lindex, 7), myFormat(0))
            .List(lindex, 8) = Format$(.List(lindex, 8), myFormat(1))
            .List(lindex, 9) = Format$(.List(lindex, 9), myFormat(1))
        Next
       
        a = .List
        '<--- this line
    End With
End Sub
should be when run userform
1.PNG



when search for specific item


ا2.PNG
 

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).

Forum statistics

Threads
1,224,823
Messages
6,181,182
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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