I'm currently struggling to create data validation drop downs, that are dependent on a previous selection
(Excel Version 16.32 on OS X)
What I want to achieve: In column F, I'd like to create data validation with the formula "=INDIRECT($Ei)" - so for cell F2 =INDIRECT(E2), cell F3 =INDIRECT(E3)
Problem: The current code works if a selection in column E has already been done. If cells in column E are empty, as it should be by default, I get an 1004 error
The code looks currently like this:
Dim currentrows As Integer
Dim i As Integer
Dim indirect_address As Variant
For Each ws In Sheets
If ws.Name <> "Overview" And ws.Name <> "Hidden" Then
currentrows = ws.UsedRange.Rows.Count
ws.Activate
With Range("E2:E" & currentrows).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=Hidden!$A$2:$A$4"
End With
For i = 2 To currentrows
indirect_address = "E" & i
With Range("F" & i).Validation
.Delete
.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
Operator:=xlBetween, Formula1:="=INDIRECT(" & Range(indirect_address).address(False, False) & ")"
End With
Next i
End If
Next ws
I'm specifically struggling with this part, since I do not understand it to it's full extend
Formula1:="=INDIRECT(" & Range(indirect_address).address(False, False) & ")"
I used following snippet before, but it this result in =INDIRECT("Ei") which does not work because of the "" in the formula
Formula1:="=INDIRECT(""" & Range(indirect_address).address(False, False) & """)"
Thanks in anticipation -CM