match function in vba working for columns but not for rows

Subho

New Member
Joined
May 31, 2012
Messages
2
Hi, this is my first try in vba coding and i am facing error with the following piece of code:

Dim x As Variant
Dim y As Variant
x = Application.Match(Me.cmbEmp_cd1.Value, Sheet3.Range("A2:A500"), False)
y = Application.Match(Me.cmbMatch.Value, Sheet3.Range("B1:XFD1"), False)
While 'y' is getting the right number ,'x' is showing "Error 2042"!!!

Need help urgently!!!

TIA
 

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
Welcome to the board..

That pretty much means the value wasn't found.

What type of data is in cmbMatch?
What type of values are in Row 1?

Are you sure there's an exact match?
Check for extra spaces
 
Upvote 0
Hi,

In Row1 the values are Charatcters while in ColumnA the vales are integers, in fact unique integers.

And I am sure it will be exact match because the values in the ComboBox 'Emp_cd1' are taken from A2:A500 itself.

Thanks.
 
Upvote 0
Looks like I missread which one worked and which one didn't..

Thanks for giving the answer to the opposite ones I asked for...

Anyway, comboboxes hold Text Strings.
Even if the source data is numeric.

So the match is looking for a "text number" in a column of real numbers.

Try
x = Application.Match(Val(Me.cmbEmp_cd1.Value), Sheet3.Range("A2:A500"), False)
 
Upvote 0
And I am sure it will be exact match because the values in the ComboBox 'Emp_cd1' are taken from A2:A500 itself.

If this is true, then you can use the ListIndex property of the combobox.

x = Me.cmbEmp_cd1.ListIndex + 1

The plus 1 is because the first index# is 0
 
Upvote 0

Forum statistics

Threads
1,203,104
Messages
6,053,543
Members
444,670
Latest member
laurenmjones1111

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