Quantcast
Channel: Active questions tagged excel - Stack Overflow
Viewing all articles
Browse latest Browse all 88835

List validation for a cell

$
0
0

I am trying to set list validation for a cell via VBA.

I use a Formula1:= when the formula is a string.

When I try to use & to combine variables, it is giving me a 400 error.

The issue with the version of Formula1 with concatenated variables seems to be that the reference cell has an #N/A value. The written formula doesn't have that problem.

Sub InsertRow()

    r = Worksheets("Kickoff Schedule").UsedRange.Rows.Count + Worksheets("Kickoff Schedule").UsedRange.Rows(1).Row - 1
    ...

    With Range("E"& r).Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
            Formula1:="=INDIRECT($D"& CStr(r) & ")"
    End With

End Sub

Full list of things I've tried and if they have/haven't worked:

' Works:
Formula1:="=INDIRECT($D19)"' Works:
MsgBox "=INDIRECT($D"& CStr(r) & ")"' MsgBox shows =INDIRECT($D19) , as expected

' Doesn't work:
Formula1:="=INDIRECT($D"& CStr(r) & ")"' Doesn't work:
Formula1:="=INDIRECT("""& Range("D"& r).Address(False, False) & """)"' Shows one option with a string of the right formula, as expected:
Formula1:="INDIRECT($D"& CStr(r) & ")"

I have already read Using Indirect function in Data Validation through VBA


Viewing all articles
Browse latest Browse all 88835

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>