I thought this would be easy. I have set up 3 radio buttons on a worksheet. Corresponding to these are 3 named ranges on a separate sheet. As each radio button is selected, I am trying to make it change the data validation list in Range("D12") to the corresponding named range.
The range names are "Running" (for running expenses), "Bills", and "Debts".
Here is the code for the first radio button. The other two are identical, except for the range name:
For some reason this breaks on the .Add line, with a run-time error 1004, "Application-defined or object-defined error."
The only suggestion I have been able to find, searching several forums, is that 1004 occurs when the name doesn't translate into a valid range. The ranges are defined dynamically, using the following formula (only column names differ between the three):
=OFFSET(Categories!$A$2,0,0,COUNTA(Categories!$A:$A)-1,1)
But I can add the validation lists manually without problems. I also tried substituting static named ranges and running the code, and it ran into the same error. So I am at a loss.
Any suggestions will be much appreciated.
The range names are "Running" (for running expenses), "Bills", and "Debts".
Here is the code for the first radio button. The other two are identical, except for the range name:
Code:
Private Sub OptionButton1_Click()
With Range("D12").Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
xlBetween, Formula1:="=Running"
.IgnoreBlank = True
.InCellDropdown = True
.InputTitle = ""
.ErrorTitle = ""
.InputMessage = ""
.ErrorMessage = ""
.ShowInput = True
.ShowError = True
End With
End Sub
The only suggestion I have been able to find, searching several forums, is that 1004 occurs when the name doesn't translate into a valid range. The ranges are defined dynamically, using the following formula (only column names differ between the three):
=OFFSET(Categories!$A$2,0,0,COUNTA(Categories!$A:$A)-1,1)
But I can add the validation lists manually without problems. I also tried substituting static named ranges and running the code, and it ran into the same error. So I am at a loss.
Any suggestions will be much appreciated.