Add Type Error: Validatelist that exceeds 255 characters

Kopko

New Member
Joined
Nov 12, 2018
Messages
5
An error have been annoying me since I recently updated Excel.

I have a string that has more than 255 characters, and I was using .AddType to write in a cell like this:

Code:
formula = "a1,a2,a3,...,a200"  'string has near 600 characters
    With ws.Range("C8").Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:=formula
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With

Maybe someone could help me with that please?
Thanks a lot!
 

Excel Facts

Whats the difference between CONCAT and CONCATENATE?
The newer CONCAT function can reference a range of cells. =CONCATENATE(A1,A2,A3,A4,A5) becomes =CONCAT(A1:A5)
Actually, the length of a string that consists of "a1,a2,a3,...,a200" is 891 characters. In any case, it was accepted when I tried it. I didn't get any errors. What type of error are you getting, and on which line? Did you assign your variable ws a worksheet object?
 
Upvote 0
Actually, the length of a string that consists of "a1,a2,a3,...,a200" is 891 characters. In any case, it was accepted when I tried it. I didn't get any errors. What type of error are you getting, and on which line? Did you assign your variable ws a worksheet object?

The string was just an example, sorry for the wrong count of characters...
I also was able to do this without any error in an old version of Excel.
Since it updated to Version 1901 (Office16), I'm getting the "RunTime Error 1004".

I believe that the error is related with the length of the string because if I minimize it to 250 characters my code works fine.

Thanks for helping me!
 
Upvote 0
I'm using Excel for Office 365 and had no issue when assigning a string having a length of approximately 8,000 characters.
 
Upvote 0
I'm using Excel for Office 365 and had no issue when assigning a string having a length of approximately 8,000 characters.
You tried to use the "Validation.AddType"?
Right now, I tried this code at my Office:
Code:
Sub test()
 formula = "AAA,BBB,AAA,BBB,AAA,BBB,CCC,DDD,EEE,AAA,BBB,CCC,DDD,EEE,AAA,BBB,CCC,DDD,EEE,AAA,BBB,CCC,DDD,EEE,AAA,BBB,CCC,DDD,EEE,AAA,BBB,CCC,DDD,EEE,AAA,BBB,CCC,DDD,EEE,AAA,BBB,CCC,DDD,EEE,AAA,BBB,CCC,DDD,EEE,AAA,BBB,CCC,DDD,EEE,AAA,BBB,CCC,DDD,EEE,AAA,BBB,CCC,DDD,EEE"  'formula with exactly 255 characters
   
    With ws.Range("C8").Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:=formula
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
End Sub

The "formula" has exactly 255 characters and in this case it is working... But if I add one more character, I get the "Run Time Error 1004".

Like I said, my old a version was running fine with no errors. The error started when my office was automatically updated.

Maybe someone can have another solution for this?

Thanks!!
 
Upvote 0
Couldn't you use a range in the data validation?
 
Upvote 0
I imagine they fixed it, since if you assign a longer string than 255 characters, the data validation will get removed when you reopen the file. You should use a range, as Norie mentioned.
 
Upvote 0
Put the values you want listed in the data validation in a list, let's say A1:A100, and use '=A1:A100' for the formula in the code.
Code:
    Formula = "=A1:A100"
   
    With Sheets(1).Range("C8").Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:=Formula
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With
 
Upvote 0

Forum statistics

Threads
1,216,577
Messages
6,131,511
Members
449,653
Latest member
andz

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