Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Holly Fox   on Jan 12 In MS Office Category.

  
Question Answered By: Arnelle Schmidt   on Jan 12

No problem. This code will do it. I assume that cell J14 will hold
your required validation  list. Put these code lines in the code
module of your worksheet (I used 'Sheet1'):


Private Sub Worksheet_SelectionChange(ByVal Target As Range)
Dim rngA As Range, rngB As Range
Dim strFormula As String

' Exit if any cell other than J14 is selected
If Target.Address <> "$J$14" Then Exit Sub

' Identify the range  of 13 dropdown  lists, starting from cell H14
Set rngA = ThisWorkbook.Worksheets("Sheet1").Range("H14:H26")

' Loop through the 13 cells
For Each rngB In rngA
' Operate only on non-blank cells
If rngB <> "" Then
' Add the values of non-blank cells  in a single string, separated by
commas.
' strFormula will be something like
' (value1,value4,value6,value7,value10,value12,)
strFormula = strFormula & rngB & ","
End If
Next rngB
' Remove the last comma
strFormula = Left(strFormula, Len(strFormula) - 1)

' Change the validation list  of cell J14
With ThisWorkbook.Worksheets("Sheet1").Range("J14").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop,
Operator:= _
xlBetween, Formula1:=strFormula
End With

End Sub


Read carefully through code comments. Check help for any keyword if
necessary.

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on Drop Down Lists Or get search suggestion and latest updates.


Tagged: