Sub DV()
Dim i As Long
Dim j As Long
Dim str1 As String
MsgBox "Beware this might crash Excel" & vbCrLf & "if you enter too large a number (>40)" & vbCrLf & "in the Inputbox." & vbCrLf & "Press CTRL+Break NOW, if you're concerned"
j = InputBox("Max elements in string", "Enter a number")
For i = 1 To j
str1 = str1 & "TAR" & i & ","
Next i
str1 = Left(str1, Len(str1) - 1)
With Sheets("Sheet1").[a1].Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:=str1
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
|