我是 VBA 新手。
是否可以使用 Vlookup 进行验证下拉列表?
例如,在 sheet1 (B2) 中有一个下拉列表,我希望 (C2) 将基于 (B2) 前 2 个字符来显示下拉列表选项。如果在 (C2) 中选择 [02 TEST2],则 (B2) 仅显示一个下拉列表,其中 app para id 为 02 选项。
(从属下拉列表在我的情况下不起作用,因为我有很多具有不同/相同 para 名称的 para ID)
This is the result I looking for
这是我的代码:
Private Sub Worksheet_Change(ByVal Target As Range)Select Case Target.Address(0, 0)
Case "B2"
If IsEmpty(Target) Then Exit Sub
Application.EnableEvents = False
Application.EnableEvents = True
Call Update_DataValidation(intRowCount)
MsgBox "" & Left(Target.Value, 2) & ""
End Select
End Sub
Private Sub Update_DataValidation(ByVal intRow As Integer)
Dim strSourceRange As String
'where I think add a vlookup range
strSourceRange = "=Sheet3!$B$2:$B$12"
With Range("C3").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=strSourceRange
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
感谢您的帮助。