validation list help

bebe1279

Board Regular
Joined
May 24, 2014
Messages
60
I'm trying to get this in cell validation list to work but I'm not having any luck so far.
this is what the code is meant to do...
open the reference wkbk & go the reference sheet
starting at col B row 2 add value of cell to ctcType collection & continue to down column B adding value of cells until cell is empty
close reference wkbk
go to contact profile sheet of the active wkbk & to range I9:J9
add validation list from ctcType collection gathered from reference wkbk
when I run code, I get "Application defined or object defined error" on this line

Code:
.Add Type:=xlValidateList, Formula1:=ctcType

Here is the whole code

Code:
Sub ProfileContactType()

'Get contact type data from reference sheet and store in ctcType collection
Dim ctcType As Collection
Dim refWb As Workbook
Dim row As Integer
Dim col As Integer

'create new collection
Set ctcType = New Collection

'open reference workbook and set var
Set refWb = Workbooks.Open("C:\AppName\Program\Reference WB.xlsm")

'assign values. column 2 or B, row 2
row = 2
col = 2

'Within the reference sheet of the reference WB
With refWb.Sheets("Reference Sheet")
    'Add cell value to collection until cells of column B is blank
    Do Until Cells(row, col).Value = ""
        ctcType.Add (Cells(row, col).Value)
        row = row + 1
    Loop
End With
    
'close reference WB
    refWb.Close
    
'Go to Contact profile sheet and contact type range, _
    create combo box and populate with collection items
With ThisWorkbook.Sheets("Contact Profile").Range("I9:J9").Validation
     .Delete
     .Add Type:=xlValidateList, Formula1:=ctcType
End With
End Sub

Thanks in advance for any help
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Hi,
not tested but see if this update to your code does what you want

Code:
Sub ProfileContactType()
    Dim refWb As Workbook
    Dim arr As Variant
    
'open reference workbook and set var
    Application.ScreenUpdating = False
    Set refWb = Workbooks.Open("C:\AppName\Program\Reference WB.xlsm", ReadOnly:=True)
    
'Within the reference sheet of the reference WB
    With refWb.Sheets("Reference Sheet")
        arr = Application.Transpose(.Range(.Range("B2"), .Range("B" & .Rows.Count).End(xlUp)).Value)
    End With
        
'Go to Contact profile sheet and contact type range, _
        create combo box and populate with range
    With ThisWorkbook.Sheets("Contact Profile").Range("I9:J9").Validation
         .Delete
         .Add Type:=xlValidateList, Formula1:=Join(arr, ",")
    End With
    
'close reference WB
     refWb.Close False
     
     Application.ScreenUpdating = True
        
End Sub

Dave
 
Upvote 0

Forum statistics

Threads
1,215,492
Messages
6,125,116
Members
449,206
Latest member
burgsrus

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