Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Drop-down values missing when using Range formula

Tags:

macos

excel

vba

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

like image 883
ManiMuthuPandi Avatar asked Feb 10 '26 11:02

ManiMuthuPandi


1 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.

like image 115
A.S.H Avatar answered Feb 13 '26 07:02

A.S.H



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!