Home » excel » excel – Drop-down values missing when using Range formula

excel – Drop-down values missing when using Range formula

Posted by: admin April 23, 2020 Leave a comment

Questions:

I am having the below VBA function. This is to create drop-down in the given cells

Public Sub CORE_SetValidation(ByRef Rng As Range, ByVal Value As String)
    With Rng.Validation
        Call .Delete
        If Value <> "" Then
            Call .Add(Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Formula1:=Value)
            .ErrorMessage = "Please select a value from drop-down list"
            .ErrorTitle = "Value Error"
            .IgnoreBlank = True
            .InCellDropdown = True
            .InputMessage = ""
            .InputTitle = ""
            .ShowInput = True
            .ShowError = True
        End If
    End With
End Sub

When I pass the values to this by comma separated values, its working fine for all the entire columns

dictkeystring = "1,2,3,4,5,6,7,8,9"
CORE_SetValidation(Sourcews.Columns(AllocationSheet_Prj_COLUMN).EntireColumn, dictkeystring)

But when I pass the values using Range formula, it doesn’t work well.

dictkeystring = "=PrjList!A2:A6"
CORE_SetValidation(Sourcews.Columns(AllocationSheet_Prj_COLUMN).EntireColumn, dictkeystring)

Problem is, For each cell I am missing one values; In first column missing one val, second cell missing 2 val, for third missing 3 values,… after some place I am missing all the values, empty drop-down I am getting

enter image description here

I am not sure why this error happen, Can I resolve this in Range formula

How to&Answers:

Try

"=PrjList!$A$2:$A$6"

Without the $, the defined range address is “relative”, so it will “slide” down with the cells of your range. i.e. the validation fr the second row will be A3:A7 and so on.

The $ in the address instructs Excel to fix the validation range, because it is an absolute address.