I am having trouble with a macro that is supposed to perform the following tasks:
Prompt the user to input a cell where the drop down list is to be located
Prompt the user for a range of data to use in the drop down list values
Create drop down list
Hide the rows in which the drop down list values are located
I originally recorded a macro to do this, and then I am tweaking the code accordingly. What is troubling me is getting the macro to select a range from an input box, the using that input to create a list. It's the partcular language included in the .Add command that I do not understand I defined the input box as a range variable celRng, and I am trying to get Formula1: = celRng. But it is not working.
I have attached the code below, and marked in which lines the errors are located:
I feel as if the bug in this code is very simple and that I am not fundamentally understanding something. Any help is greatly appreciated!
DJL
Prompt the user to input a cell where the drop down list is to be located
Prompt the user for a range of data to use in the drop down list values
Create drop down list
Hide the rows in which the drop down list values are located
I originally recorded a macro to do this, and then I am tweaking the code accordingly. What is troubling me is getting the macro to select a range from an input box, the using that input to create a list. It's the partcular language included in the .Add command that I do not understand I defined the input box as a range variable celRng, and I am trying to get Formula1: = celRng. But it is not working.
I have attached the code below, and marked in which lines the errors are located:
Code:
Sub CreatDropDownList()
'
' CreatDropDownList Macro
'
' Keyboard Shortcut: Ctrl+Shift+D
'
Dim celNm, celRng As Range
On Error Resume Next
Application.DisplayAlerts = False
Set celNm = Application.InputBox(Prompt:= _
"Please select a cell to create a list.", _
Title:="SPECIFY Cell", Type:=8)
On Error GoTo 0
Application.DisplayAlerts = True
If celNm Is Nothing Then
Exit Sub
Else
With Selection.Validation
.Delete
On Error Resume Next
Application.DisplayAlerts = False
Set celRng = Application.InputBox(Prompt:= _
"Please select the range of cells to be included in list.", _
Title:="SPECIFY RANGE", Type:=8)
On Error GoTo 0
Application.DisplayAlerts = True
If celRng Is Nothing Then
Exit Sub
Else
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, _
Formula1:=celRng 'THIS IS WHERE THE ERROR HAPPENS
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End If
End With
End If
Range("celRng").Select 'ALSO ANOTHER ERROR HAPPENS HERE
Selection.EntireRow.Hidden = True
End Sub
I feel as if the bug in this code is very simple and that I am not fundamentally understanding something. Any help is greatly appreciated!
DJL