How to find the row number of a number in a list?

novicevba

New Member
Joined
Apr 7, 2011
Messages
3
I have a database in excel. Each row contains a unique number in column A. Column A is not not in any numeric order. I have a userform which has a text box (textbox1) in which I need to be able to type a number and then press a button (CommandButton9) to find the row number which that number is in.

The code works if I put text in the column that I am searching and search for the text, but it doesnt work when I look for numbers. The code is;

Dim x As Long
x = Application.WorksheetFunction.Match(TextBox1.Text, Range("a1:a1048576"), 0)
Range("a1").Offset(x - 1, 0).Select

When I try to use this code to find a number it does not work and I get a run time 1004 error - Unable to get the match property of the worksheetfunction class.

Please help!

Thanks
 
Last edited:

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
novicevba,

Welcome to the MrExcel forum.


Try:

Code:
x = Application.Match(TextBox1.Text, Range("a1:a1048576"), 0)

'Or:

x = Application.Match(TextBox1.Text, Columns(1), 0)
 
Upvote 0
Hi Hiker 95.

I tied the amendments that you suggested and they both returned an error: runtime error '13' - type mismatch.

I dont understand why my code works with text but not numbers. Do you have any ideas why this might be? I have tried typing the match function in the database to find the cell reference and this works, and as I mentioned when I use my code to find text in the column it works fine.

Any other ideas would be much appreciated.
 
Upvote 0
Hello Noviceba,

I don't have any knowledge in VBA, but I think the problem occurs MATCH couldn't found the lookup_value in the lookup_array. try something like this;

Code:
Sub Test()
On Error GoTo XX
Dim X As Long
    X = Application.Match(Range("D1"), Range("A:A"), 0)
    Range("A" & X).Select
Exit Sub
XX:
MsgBox "Couldn't found " & Range("D1").Value
End Sub
replace range with your textbox.
 
Upvote 0
Hi Haseeb,

Thanks for replying to my question.

I tried your code and I still seem to have the same problem in that it works if I try to find text but if I try to find a number then it fails.

I am totally confused?
 
Upvote 0
Have you tried the FoundCell function - instead of match - IDK if it will solve the problem - Buy worth a try.
 
Upvote 0

Forum statistics

Threads
1,215,620
Messages
6,125,876
Members
449,268
Latest member
sGraham24

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