Match function doesn't work

AveryHilditch

New Member
Joined
Oct 26, 2021
Messages
4
Office Version
  1. 2013
Platform
  1. Windows
I am developing an app where I need to get the content of column 1 in a row selected by the user. When I run the app, a list box is populated with the contents of a table. I am currently working on an Update data function. Double clicking a row successfully populates the fields in a form. The first image shows some of the form and the second the list box.

Excel Error 2.jpg


Excel Error.jpg


If I double click a row, the data in the selected row is copied to the form. If I then click the Update button I have placed on the form, the contents of the form are copied back to the selected row in the list box and data table.

I am using the following code:

Private Sub UpdateBtn_Click()
Dim Selected_Row As Long
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Data")
Selected_Row = Application.WorksheetFunction.Match(Me.TextBox1.Value, sh.Range("A:A"), 0)

'... More code

End Sub

When I run the code, I get runtime error 1004 "Unable to get the Match property of the WorksheetFunction class"

I have used exactly the same function without any issues in other apps but not in this one. I am tearing my hair out trying to work out why it isn't working

Thank you
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi & welcome to MrExcel.
What is in textbox1?
 
Upvote 0
I am developing an app where I need to get the content of column 1 in a row selected by the user. When I run the app, a list box is populated with the contents of a table. I am currently working on an Update data function. Double clicking a row successfully populates the fields in a form. The first image shows some of the form and the second the list box.

View attachment 49865

View attachment 49866

If I double click a row, the data in the selected row is copied to the form. If I then click the Update button I have placed on the form, the contents of the form are copied back to the selected row in the list box and data table.

I am using the following code:

Private Sub UpdateBtn_Click()
Dim Selected_Row As Long
Dim sh As Worksheet
Set sh = ThisWorkbook.Sheets("Data")
Selected_Row = Application.WorksheetFunction.Match(Me.TextBox1.Value, sh.Range("A:A"), 0)

'... More code

End Sub

When I run the code, I get runtime error 1004 "Unable to get the Match property of the WorksheetFunction class"

I have used exactly the same function without any issues in other apps but not in this one. I am tearing my hair out trying to work out why it isn't working

Thank you
Oops. I should have said that TextBox2 contains the number of the selected row.

I get this error regardless of which data row I select
 
Upvote 0
But your code is trying to match textbox1 not textbox2
 
Upvote 0
But your code is trying to match textbox1 not textbox2
I really shouldn't be trying to work in the early hours! TextBox1 contains the number of the selected row.

I made TextBox1 visible to show you that I am actually getting the row number in that field

If it will help, this is the code executed when I double click the List Box

Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean)
Me.TextBox1.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 0)
Me.VerifiedCB.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 1)
Me.MembershipCB.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 2)
Me.PaidCB.Value = Me.ListBox1.List(Me.ListBox1.ListIndex, 3)
End Sub
 

Attachments

  • Clipboard01.jpg
    Clipboard01.jpg
    9.6 KB · Views: 10
Upvote 0
Ok, try
VBA Code:
Selected_Row = Application.WorksheetFunction.Match(Val(Me.TextBox1.Value), sh.Range("A:A"), 0)
 
Upvote 0
Solution
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,885
Messages
6,122,090
Members
449,065
Latest member
Danger_SF

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