In cell drop down list data validation Excel VBA

bebe1279

Board Regular
Joined
May 24, 2014
Messages
60
Hi everyone

I’m trying to get an in cell data validation dropdown to work and I’m having no luck. Any help is appreciated.

Here’s what I’ve got…

I have two workbooks in the same folder
1. Reference Worksheets
2. Profile worksheets

The Reference workbook contains (as of now, this may change) one sheet named “Reference sheet”. This sheet consists of single column dynamic named ranges (all columns contain headings) that I’m trying to use to populate in cell drop down lists for worksheet forms I’ve designed in the “Profile worksheets” workbook.

This is the formula I’m using to define my dynamic named ranges. This example is for the list in column C.

Code:
=OFFSET('Reference Sheet'!$C$1,1,0,COUNTA('Reference Sheet'!$C:$C)-1,1)

This is the code that I’m using to create and populate the in cell drop down list in the “Profile Worksheets” workbook.

Code:
Sub populatePrefixList()
 
With Range("B12").Validation
    .Add Type:=xlValidateList, _
        AlertStyle:=xlValidAlertStop, _
        Operator:=xlBetween, _
        Formula1:="=[Reference Worksheets]!Prefix"
    .InCellDropdown = True
                      
End With
End Sub

Prefix = named range in column C
Note: Reference Worksheets is meant to be closed when this code will be executed.

When I run it, I get the following error:

Runtime error 1004 – Application defined or object defined error
I think it has to do with the formula1 reference, but I’m not sure how to fix it.
 

Some videos you may like

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.

Watch MrExcel Video

Forum statistics

Threads
1,122,670
Messages
5,597,483
Members
414,146
Latest member
marginmakerb

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
Top