Setting Up Cell Validation List WIth A Dynamic Named Range - Error

Ark68

Well-known Member
Joined
Mar 23, 2004
Messages
4,564
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I am trying to set up a list cell validation on my worksheet based on a dynamic named range.

Rich (BB code):
        str_vlist = "nm_acct_" & Range("M9").Value
        Range("O9:P9").Locked = False
        
        Range("O9").Validation.Delete
        Range("O9").Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
            Formula1:=("=str_vlist")

I am getting an error with the line in red. ("Application-defined or object-defined error.)
I assume it's because it's looking for a named range "str_vlist" which doesn't exist. How do I adjust this code to apply the range named as represented by the variable str_vlist?
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
VBA Code:
nm_acct_
what???
Can you post the whole code please?
 
Upvote 0
I can't post the whole 2000 line code with network referenced drives and confidential information.
I just need to know how to replace str_vlist which is a variable, not a name, with a dynamic name.
str_vlist is a variable combining the static text "nm_acct_" with a dynamic value from Range("M9") of my workbook,

So if cell M9 = "SD" then the value of str_list is "nm_acct_SD". This is a name of a named range that I need to plug into the validation.add script. The named range is "nm_acct_SD", not "str_list"

If I wasn't dealing with a dynamic list, the code would simply be :

Code:
Range("O9").Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, _
            Formula1:=("=nm_acct_SD")

But "nm_acct_SD" is variable.
 
Upvote 0
Code:
Formula1:="=" & str_vlist

otherwise you're literally passing the text "str_vlist", not the contents of the variable.
 
Upvote 0
Solution
Yeah Rory, that's what I was looking for.
I tried
Code:
Formula1:=("=str_vlist")
and
Code:
Formula1:=str_vlist
with no love.
Seems I needed to find a happy medium.

Thank you!
 
Upvote 0

Forum statistics

Threads
1,215,022
Messages
6,122,726
Members
449,093
Latest member
Mnur

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top