別のセルからの選択に基づいて、あるセル内の複数の値をvlookupしようとしています。1つのセル内で複数の値を調べる
私は「GymIDs」が自動的に入力される単一の「Gym」を選択する以下の表を持っています。私はその後、複数の "Gyms"を選択できるように、以下のVBAを使用しました。また、複数の "GymIDs"を表示したいと思います。
現在VLOOKUP = VLOOKUP(M7、無視F1:!G300,2、FALSE)複数選択のための
for some reason I could only upload one image so put them all together
VBAコード
Private Sub Worksheet_Change(ByVal Target As Range)
'Code by Sumit Bansal from https://trumpexcel.com
' To Select Multiple Items from a Drop Down List in Excel
Dim Oldvalue As String
Dim Newvalue As String
On Error GoTo Exitsub
If Not Intersect(Target, Range("M7:M30")) Is Nothing Then
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
GoTo Exitsub
ElseIf Target.Value = "All" Then GoTo Exitsub
ElseIf Target.Value = "Select" Then GoTo Exitsub
ElseIf Target.Value = "" Then GoTo Exitsub
Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
If Oldvalue = "" Then
Target.Value = Newvalue
ElseIf Oldvalue = "All" Then
Target.Value = Newvalue
ElseIf Oldvalue = "Select" Then
Target.Value = Newvalue
Else
Target.Value = Oldvalue & ", " & Newvalue
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub
参照編1:[StackOverflowの](https://stackoverflow.com/questions/14803944/Excelで複数の用語を検索する)Reference2:[Stackoverflow](https://stackoverflow.com/questions/19504858/find-all-matches-in-workbook-using-excel -vba) – mgae2m