Setting a cell's validation data from a macro

jdvorak

New Member
Joined
Mar 4, 2010
Messages
10
I am writing an application in vba for excel and need to set the validation list for each cell in a specific column. I have the following code to do this:

Code:
Public Sub setReviewerCellValidation(reviewers() As String)
    Dim str As String
    Dim cnt As Integer
    For cnt = 0 To UBound(reviewers)
        If cnt = 0 Then
            str = reviewers(0)
        Else: If reviewers(cnt) <> "" Then str = str & ", " & reviewers(cnt)
        End If
    Next
    
    For Each cell In Range(getColumnRange(RegularReviewerCol))
        cell.Validation.Delete
        cell.Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
                    xlBetween, Formula1:=str
        cell = ""
   Next
    
End Sub

The string 'str' passed to the Formula1 parameter is series of comma separated names (ex: "name1, name2, name3"). However, when the sub executes, I get the following error message:

Code:
Automation error
The object invoked has disconnected from its clients

Anybody know what this means and how to resolve it? Thanks

Joe
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"

Forum statistics

Threads
1,223,099
Messages
6,170,114
Members
452,302
Latest member
TaMere

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