Wildcard filter and user prompt to search for material number in excel

chewjekhui

New Member
Joined
Aug 16, 2018
Messages
3
Hi there,

I need some help in terms of the code I require for prompting the user to key in the material number and using that material number as a wildcard filter to search the excel sheet and copy the values from 2 columns and copy the material numbers that contain the search term and paste it to a new excel sheet.

For example: HBA12906250000 and HBA12906280AZ0 . The alphanumeric number after HBA129062 changes and might repeat. So I want a user prompt that allows the user to key in HBA129062 and all possible combinations of that to be copied and pasted in a new sheet.

It then also copies and paste the plant stock value and plant stock value alongside with the material numbers copied earlier.
Material NumberTypeStd CostMaterialPlant stockPlant stock value
HBA12906250000YRAW BAR 11.8201.5117.85
HBA12906250000YRAW BAR 22.14133730.62
HBA12906280AZ0YRAW BAR 39.6419.375371.63
HBA12906280AZ0YRAW BAR 10.641144.51537.48
HBA12906250000YRAW BAR 1.88147.12588.6
HBA137030500000YRAW BAR 3.7197.072359.17
HBA137030800000YRAW BAR 5.1118.594.35
HBA137030500000YRAW BAR 20.871126.012629.83
HBA137030800000YRAW BAR 27.9818.375234.33
HBA137030900000YRAW BAR 22.8415.376122.79
HBA137030900000YRAW BAR 17.68113.02230.19

<colgroup><col><col><col><col span="3"><col></colgroup><tbody>
</tbody>

I have been searching around forums and so far I am only able to find code that has the search criteria fixed in the VBA code. Could not get wildcard filter VBA codes.

Any help is greatly appreciated
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
use HBA129062*
also u can use winautomation to automate all kind of excel to excel and excel to any oracel form and to web
 
Upvote 0
I want the user to type n the results come out in a certain format.... hence not using the filter function in excel
 
Upvote 0
Hello Chewjekhui,

Try the following code placed in a standard module and assigned to a button:-


Code:
Sub Test()

        Dim MatNum As String

Application.ScreenUpdating = False

        MatNum = InputBox("Please enter the first nine characters of the required material number.")
        If MatNum = vbNullString Then Exit Sub
        
Sheet2.UsedRange.Offset(1).Clear

With Sheet1.[A1].CurrentRegion
        .AutoFilter 1, "*" & MatNum & "*"
        .Offset(1).EntireRow.Copy Sheet2.Range("A" & Rows.Count).End(3)(2)
        .AutoFilter
End With

Sheet2.Columns.AutoFit
Application.ScreenUpdating = True

End Sub

Following is the link to a sample file using the data you supplied in your opening post:-

http://ge.tt/4LQGHgu2

When you click on the "GO" button, an InputBox will appear asking you to enter the first nine characters from a material number. Click OK in the InPutBox and the code will filter for any material numbers starting with the nine characters and then transfer the relevant rows of data to Sheet2.

I hope that this helps.

Please test the code in a copy of your workbook first.

Cheerio,
vcoolio.
 
Upvote 0

Forum statistics

Threads
1,215,148
Messages
6,123,301
Members
449,095
Latest member
Chestertim

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