Goal
I would like to loop through three sheets (I'm starting with one), look for a certain Type in column C and automatically populate/autopopulate a In-cell dropdown (similar to the one found in the Data Validation settings) in column D. The In-cell dropdown should list values for all Types but should autopopulate with the value belong to the Type.
Problem
The code below populates every In-cell dropdown list with the same value, namely Type1's Item1--Item2--Item3--Item4.
I don't know how to list all values and at the same time autopopulate the cell.
Desired output
Code
For the sake of simplicity, I have only added the two first types in the code below.
Sub AutoDropdown()
Dim PersonSource As Range
Dim PersonSourceTotal As Range
Dim PersonCell As Range
'Dim ws As Worksheet
Dim i As Integer
Dim lastRow As Integer
Set PersonSourceTotal = Sheets("Sheet1").Range("D2:D200")
With PersonSourceTotal.Offset(0, -2)
lastRow = .Cells(.Rows.Count, PersonSourceTotal.Columns.Count).End(xlUp).Row
End With
Set PersonSource = Sheets("sheet1").Range("D2:D" & lastRow)
On Error Resume Next
For Each PersonCell In PersonSource
Name = PersonCell.Offset(0, -3)
ID = PersonCell.Offset(0, -2)
If Name <> "" And ID <> "" Then
For i = 0 To lastRow
If PersonCell.Offset(i, -1) = "Type1" Then
arr1 = Array("Item1", "Item2", "Item3", "Item4")
arr1Merged = Join(arr1, "--")
With PersonCell.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=arr1Merged
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
ElseIf PersonCell.Offset(i, -1) = "Type2" Then
arr2 = Array("Item5", "Item6", "Item7", "Item8", "Item9")
arr2Merged = Join(arr2, "--")
Debug.Print (arr2Merged)
With PersonCell.Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:=arr2Merged
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End If
Next i
Else
MsgBox "Remember to add Name and ID"
End If
Next PersonCell
End Sub