filtering/searching for numeric VBA userform

bry02

New Member
Joined
Dec 10, 2022
Messages
2
Office Version
  1. 2019
  2. 2016
Platform
  1. Windows
Hi I have a UserForm that has a filter Combobox that filters different criteria. and that includes "Year" and a TextBox which will be the search box. and a listbox that will show result

Note: "Year" is in separate column ("T")

the search box is working fine for other criteria, except for "Year" which is encoded only by Numeric (Ex. 2022)

for example if I filter it by "Year" then search for "2022"

It will not show any result even do there is a row/data that contains 2022 under Year column

but, if I edit the data and add a alphabet together with numeric ex "2022A"

and then filter it again by year and search. it will show the data .

for short it does not recognize numeric only in data unless it has an alphabet.
his is how i populate my combobox

Sub Refresh_DropDown_List()

Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("List")

Dim dsh As Worksheet
Set dsh = ThisWorkbook.Sheets("Data")

VBA Code:
Filter_by List'
With Me.cmb_Filter_By1
    .Clear
    .AddItem "ALL"
    .AddItem "Year" '<--- i added this year according to column name in headers
    .AddItem "Week"
    .AddItem "Line"
    .AddItem "Machine"
    .AddItem "Description"
    .AddItem "Possible Cause"
    .AddItem "Corrective Action"
    .AddItem "Action to be taken"
    .AddItem "product"
    .AddItem "Factor"
    .AddItem "Status"
    .AddItem "Incharge"
    .AddItem "Note"
    .Value = "ALL"

End With
End Sub

his is how i Search and pupulate listbox

Code:
Sub Refresh_Listbox()

Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Data")

Dim dsh As Worksheet
Set dsh = ThisWorkbook.Sheets("Data_Display")

''''''''''' Copy Data ''''''''''
dsh.Cells.Clear
sh.AutoFilterMode = False

If Me.cmb_Filter_By2.Value <> "ALL" Then
  sh.UsedRange.AutoFilter Application.WorksheetFunction.Match(Me.cmb_Filter_By2.Value, sh.Range("1:1"), 0), "*" & Me.txt_Search2.Value & "*"
End If

Dim lr As Long

On Error Resume Next

lr = Application.WorksheetFunction.CountA(dsh.Range("A:A"))

If lr = 1 Then lr = 2

With Me.ListBox1
    .ColumnHeads = True
    .ColumnCount = 25
    .ColumnWidths = "35,33,30,100,70,44,60,120,120,120,120,70,100,50,70,70,70,70,200,50,100"
    .TextAlign = fmTextAlignCenter
    .RowSource = "Data_Display!A2:U" & lr

    
End With

End Sub

so what I was looking for is to be able to filter it by Year and search it just by typing the whole numeric "2022" or numeric key "22"

or if its possible if i could only search between from "date" up to this "date"

Thanks in advance.

BTW: i am not an expert nor a coder, i only learn by reading, asking question and watching youtube guides
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
s
Welcome to the MrExcel Message Board!

Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at:

If you have posted the question at more places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.

sorry about that please delete this post
 
Upvote 0

Forum statistics

Threads
1,223,936
Messages
6,175,499
Members
452,649
Latest member
mr_bhavesh

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