Match Function in VBA only working for Letters not numbers

bchacket

New Member
Joined
Jul 10, 2014
Messages
6
I am pretty new to VBA and have learned most of what I know on this site. So I figured if I had a question I couldn't find the answer to this would be the site to come to. I am trying to create a sheet that is a database of parts. I have created a user form that lets you fill in the different information and then prints it. I am now trying to make the form look up all the information on a part if it already exists and print it in the correct text box. The problem I am having is that the Match function won't work with numbers and all my part numbers are only numbers. If I try having a part number named "PartPart" for instance it will work though. Here is my code below. Between the ** is where the error starts.

Code:
Sub GWNumberTextBox_AfterUpdate()


On Error GoTo 0


Dim CusNameRange As Range
Dim ThreeCusNameRange As Range
Dim GWnumber As String
Dim ThreeGW As String
Dim SheetRange As Range
Dim GWNumRange As Range


Set SheetRange = Worksheets("Parts").Range("$A$8:$X$1000")
Set GWNumRange = Worksheets("Parts").Range("$A$1:$A$4")
Set CusNameRange = Worksheets("List Contents").Range("$E$12:$F$770")
Set ThreeCusNameRange = Worksheets("List Contents").Range("$F$12:$F$770")


    GWnumber = GWNumberTextBox.Value
    ThreeGW = Left(GWnumber, 3)


On Error Resume Next


    CusNameTextBox.Value = Application.WorksheetFunction.Index(CusNameRange,
Application.WorksheetFunction.Match(ThreeGW, ThreeCusNameRange, False), 1)
     *CusPartNumTextBox.Value = Application.WorksheetFunction.Index(SheetRange, Application.WorksheetFunction.Match(GWnumber, GWNumRange, 0), 2)*
    CusNameTextBox.Value = Application.WorksheetFunction.Index(SheetRange, Application.WorksheetFunction.Match(GWnumber, GWNumRange, 0), 6)
    DivisionComboBox.Value = Application.WorksheetFunction.Index(SheetRange, Application.WorksheetFunction.Match(GWnumber, GWNumRange, 0), 8)
    PartStatusComboBox.Value = Application.WorksheetFunction.Index(SheetRange, Application.WorksheetFunction.Match(GWnumber, GWNumRange, 0), 9)
    MoldStatusComboBox.Value = Application.WorksheetFunction.Index(SheetRange, Application.WorksheetFunction.Match(GWnumber, GWNumRange, 0), 10)
    MoldLocationComboBox.Value = Application.WorksheetFunction.Index(SheetRange, Application.WorksheetFunction.Match(GWnumber, GWNumRange, 0), 11)
    
End Sub
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Welcome to the board.

I believe the problem is that a TextBox contains....well...TEXT.
Even if it 'looks like' a number, it's still considerd a Text String.

Not to mentino that GWNumber is Dimmed as a String...

Try changing that to Dim as Double or Long if it's a whole number.
And use
GWnumber = Val(GWNumberTextBox.Value)
 
Upvote 0
But I'm completely fine with it being a string I don't need the value but i will try that thanks.
 
Upvote 0
If the values you're matching it against (GWNumRange) are actually numbers, then GWnumber must also be a number, not a string.
 
Upvote 0

Forum statistics

Threads
1,215,456
Messages
6,124,939
Members
449,197
Latest member
k_bs

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