lostitagain
New Member
- Joined
- Jul 5, 2012
- Messages
- 21
Using Excel 2010 in Windows 7 32-bit
I am attempting to use a vba macro to generate a number of drop down lists depending on how many entries the user requires.
Each entry consists of the entry number, a data validation list, and a dependent data validation list.
and should look like:
[TABLE="width: 447"]
<TBODY>[TR]
[TD]Number of Entries:</SPAN>
[/TD]
[TD="align: right"]3</SPAN>
[/TD]
[TD][/TD]
[TD]Entry #</SPAN>
[/TD]
[TD]List</SPAN>
[/TD]
[TD]Selection</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]1</SPAN>
[/TD]
[TD]List1</SPAN>
[/TD]
[TD]Choice A</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2</SPAN>
[/TD]
[TD]List 3</SPAN>
[/TD]
[TD]Choice X</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]3</SPAN>
[/TD]
[TD]List 2</SPAN>
[/TD]
[TD]Choice 3</SPAN>
[/TD]
[/TR]
</TBODY>[/TABLE]
Where each item in the List column is a Data Validation drop down to choose which List to select from and each item in the Selection Column is a dependent Data Validation drop down that is dependent on the choice on the same row in the list column.
Generating multiple data validation lists works fine. The code generates a Runtime Error '1004': application-defined or object defined error at the line in red. I'm pretty sure it has to do with the syntax of the Indirect statement using a variable for the row number but I am unable to correct it.
Any help would be appreciated.
I am attempting to use a vba macro to generate a number of drop down lists depending on how many entries the user requires.
Each entry consists of the entry number, a data validation list, and a dependent data validation list.
and should look like:
[TABLE="width: 447"]
<TBODY>[TR]
[TD]Number of Entries:</SPAN>
[/TD]
[TD="align: right"]3</SPAN>
[/TD]
[TD][/TD]
[TD]Entry #</SPAN>
[/TD]
[TD]List</SPAN>
[/TD]
[TD]Selection</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]1</SPAN>
[/TD]
[TD]List1</SPAN>
[/TD]
[TD]Choice A</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]2</SPAN>
[/TD]
[TD]List 3</SPAN>
[/TD]
[TD]Choice X</SPAN>
[/TD]
[/TR]
[TR]
[TD][/TD]
[TD][/TD]
[TD][/TD]
[TD]3</SPAN>
[/TD]
[TD]List 2</SPAN>
[/TD]
[TD]Choice 3</SPAN>
[/TD]
[/TR]
</TBODY>[/TABLE]
Where each item in the List column is a Data Validation drop down to choose which List to select from and each item in the Selection Column is a dependent Data Validation drop down that is dependent on the choice on the same row in the list column.
Generating multiple data validation lists works fine. The code generates a Runtime Error '1004': application-defined or object defined error at the line in red. I'm pretty sure it has to do with the syntax of the Indirect statement using a variable for the row number but I am unable to correct it.
Any help would be appreciated.
Code:
Sub FillDataEntry()
'Declare Variables
Dim i, EntryNum As Integer
'Store the number of entries a user wishes to make
EntryNum = Range("B1").Value
'Initialize i as 2 since it is the row that the entries start on
i = 2
'Loops to create a number of lists equal to the user entry
While i < 2 + EntryNum
'Enters the Entry number
Range("D" & i) = i - 1
'Main List for the E column
With Range("E" & i).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=List"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
'Makes a list in the F column that is dependent on the list in the E column
With Range("F" & i).Validation
.Delete
[COLOR=#ff0000] .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Indirect(E" & i & ")"
[/COLOR] .IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
i = i + 1
Wend
End Sub