我想知道如何使用application.worksheetfunction.match(lookup_value, lookuparray, match type)
编辑:
这是"假设"成为一个按钮(保留按钮)" ReservationName"是一个文本框,保留按钮将可用列表框中的数字添加到保留列表框,然后删除在可用列表框中选择的数字。我是编码的初学者,所以请注意我的错误。 非常感谢。
Private Sub ReserveButton_Click()
Dim Locator, RowData, NListBoxValue As Double
Locator = Application.WorksheetFunction.Count(Worksheets("Reserved").Range("A:A"))
For r = 0 To AvailableNumberList.ListCount - 1
RowData = Application.WorksheetFunction.Match(AvailableNumberList.List(r), Worksheets("Activation").Range("A:A"), 0)
If AvailableNumberList.Selected(r) = True Then
If ReservationName.Value = "" Or ReservationName.Value = "Enter Full Name" Then
ErrorResult = MsgBox("Error: Name field is empty", vbCritical + vbOKOnly, "Error In Field")
ElseIf Application.WorksheetFunction.VLookup(AvailableNumberList.List(r), Activation.Range("A:E"), 4, False) <> "FREE" Then
ErrorResult = MsgBox("Error: Number is Not Free", vbCritical + vbOKOnly, "Error In Reservation")
Else
ReservedNumberList.AddItem AvailableNumberList.List(r)
Worksheets("Reserved").Range("A" & Locator + 2) = AvailableNumberList.List(r)
Worksheets("Reserved").Range("B" & Locator + 2) = Worksheets("Activation").Cells(RowData, 2)
Worksheets("Reserved").Range("C" & Locator + 2) = Worksheets("Activation").Cells(RowData, 3)
Worksheets("Reserved").Range("D" & Locator + 2) = ReservationName.Value
AvailableNumberList.Clear
Worksheets("Reserved").Rows(RowData).Delete
ThisWorkbook.Save
Call AvailableList
End If
End If
Next r
End Sub
答案 0 :(得分:1)
Application.WorksheetFunction.Match(<Form>.<Listbox>,Range("<LookupSheet>!A:A"),0)