简体   繁体   English

VBA EXCEL:使用列表框中的值作为Match WorksheetFunction中的Lookup值

[英]VBA EXCEL: Use value in Listbox as Lookup value in the Match WorksheetFunction

I would like to know how to lookup a value selected from a Listbox (clicked) using application.worksheetfunction.match(lookup_value, lookuparray, match type) 我想知道如何使用application.worksheetfunction.match(lookup_value, lookuparray, match type)查找从列表 application.worksheetfunction.match(lookup_value, lookuparray, match type)选择的值(单击application.worksheetfunction.match(lookup_value, lookuparray, match type)

edit: 编辑:

This is a "supposed" to be a button (Reservebutton) the "ReservationName" is a textbox the reserve button adds the number from the available listbox to the reserved listbox and then deletes the number selected in the available listbox. 这是一个“应该”作为按钮(Reservebutton),“ ReservationName”是一个文本框,保留按钮将数字从可用列表框中添加到保留列表框中,然后删除在可用列表框中选择的编号。 i'm a beginner in coding, so mind my mistakes please. 我是编码的初学者,所以请注意我的错误。 thanks a lot. 非常感谢。

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

码:

Application.WorksheetFunction.Match(<Form>.<Listbox>,Range("<LookupSheet>!A:A"),0)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM