Forum Discussion
Excel sheets that populate a drop down menu
Hello lowdencaft,
Yes, this is possible by combining Data Validation, INDIRECT, and VBA.
Step 1: Dropdown - Select your MACHINE NAME cells, go to Data → Data Validation → List, and either type sheet names or point to a range with the names.
Step 2: Pull data with INDIRECT - Assuming the dropdown is in I2 and hardware is in J2 on the machine sheet, use =IFERROR(INDIRECT("'" & $I2 & "'!J2"), "") and repeat for other fields by changing the cell reference.
Step 3: VBA for automatic dropdown and auto-fill- Sub PopulateMachineDropdown() Dim ws As Worksheet, mainWS As Worksheet, sheetNames As String Set mainWS = ThisWorkbook.Sheets("RJ45") mainWS.Columns("B").Validation.Delete For Each ws In ThisWorkbook.Sheets If ws.Name <> mainWS.Name Then sheetNames = sheetNames & ws.Name & "," Next ws sheetNames = Left(sheetNames, Len(sheetNames) - 1) With mainWS.Range("B2:B100").Validation .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:=sheetNames .IgnoreBlank = True: .InCellDropdown = True End With End Sub Private Sub Worksheet_Change(ByVal Target As Range) Dim ws
As Worksheet, selectedSheet As String If Not Intersect(Target, Me.Columns("B")) Is Nothing Then Application.EnableEvents = False selectedSheet = Target.Value On Error Resume Next Set ws = ThisWorkbook.Sheets(selectedSheet) On Error GoTo 0 If Not ws Is Nothing Then Target.Offset(0, 1).Value = ws.Range("J2").Value Target.Offset(0, 2).Value = ws.Range("K2").Value Else Target.Offset(0, 1).Resize(1, 2).ClearContents End If Application.EnableEvents = True End If End Sub Result: Dropdown auto-lists all machine sheets, and selecting a machine fills adjacent fields automatically.