IN VBA create a Data Vaildation List from a Case Selection
is it possible to create a data Validation List from a Case Selection
ie
Code:
With Range("E9").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="= Case X"
'the X comes from Case
Dim SectorType As Integer
Worksheets("Input").Select
SectorType = Range("T34").Value
Select Case SectorType
Case 1 = "='WORKSHEET#1'!$A$8:$J$8"
Case 2 = "='WORKSHEET#2!$A$8:$J$8"
End Select
I'm struggling with this one
I tried this and then I puller my hair out
Code:
Sub CreateValidation(CellLocation As Range, _
ValidationList As Variant, _
Optional sInputTitle As String, _
Optional sErrorTitle As String, _
Optional sInputMessage As String, _
Optional sErrorMessage As String)
With Range(CellLocation.Address).Validation
.Delete
.Add Type:=xlValidateList, Formula1:=Join(ValidationList, ",")
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = sInputTitle
.ErrorTitle = sErrorTitle
.InputMessage = sInputMessage
.ErrorMessage = sErrorMessage
.ShowInput = True
.ShowError = True
End With
Dim SectorType As Long
Dim ValList As Variant
SectorType = Range("T34")
Select Case SectorType
Case Is = 1
ValList = Range("T41,T45")
Case Is = 2
ValList = Range("U41,U45")
End Select
CreateValidation ActiveSheet.Range("S41"), ValList
End Sub
**** I want the list to come from a range on the sheet ****