Using Match function and comboboxes in VBA

neilybig

New Member
Joined
Dec 2, 2018
Messages
9
Hi,
I am trying to locate a specific row number using vba. I need it to be able to look at the contents of a combobox and search for this value in the worksheet and then return the row number that the function returns.

Once I have this value (lRow) I can use this as a cell reference

Using the below I get Run-time error 13 - Type mismatch

Code:
Private Sub CommandButton1_Click()
Dim lRow As Integer
lRow = Application.Match(ComboBox1.Value, Sheets("Trial Tracker").Range("A:A"), 0)
Cells(lRow, 14).Value = TextBox3.Value
Cells(lRow, 15).Value = TextBox4.Value
End Sub

Many Thanks as always
Neil
 

Excel Facts

What is the shortcut key for Format Selection?
Ctrl+1 (the number one) will open the Format dialog for whatever is selected.
Hi,

Are you in a situation where you must have a Match ... ? If no, you do have to deal with the potential errors ....

Also ... you do have to make the Format of your ComboBox remains consistent with the data located in Column A of your worksheet ...

Hope this will help
 
Upvote 0
Hi,
Thanks for coming back to me. It should always match as the combobox is referencing the same list. How do I check formatting? as it is reading 1,2,3,4 etc so I think it is okay

Neil
 
Upvote 0
Hi Neil,

Most probably your combobox does contain Text ... (even if visually you see 1,2,3 ...)

and your column A ... with almost the same info shows 1,2,3 ... but within the sheet they are considered as Numbers ...

If that is the case ...you could test the CInt() function ...

Code:
[COLOR=#333333]lRow = Application.Match(CInt(ComboBox1.Value), Sheets("Trial Tracker").Range("A:A"), 0)[/COLOR]

Hope this will help
 
Upvote 0

Forum statistics

Threads
1,223,903
Messages
6,175,289
Members
452,631
Latest member
a_potato

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