PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 4.00 average.

Data validation list limit

 
 
BartM
Guest
Posts: n/a
 
      21st Sep 2008
I use VBA to impose data validation to a certain cell. Below is a simple
example. This works fine and a drop down list is displayed as expected. When
I save the workbook and open it again Excel complains with the well known
"...unreadable content...." message. There seems to be a limit to length of
the validation list that is not applied when imposing the data validation
list by VBA, but is applied when Excel (re)opens the book. Anyone any
suggestions, ideas? I am currently deleting all validation lists when the
workbook is closed but that is hardly an ideal situation.

Private Sub SetValidationList(ByVal R As Range, ByVal List As String)
R.Validation.Delete

With R.Validation
.Add Type:=xlValidateList, _
AlertStyle:=xlValidAlertStop, _
Formula1:=List
.InCellDropdown = True
End With
End Sub

Private Sub Workbook_Open()
Dim R As Range
Dim i As Integer
Dim S As String

Set R = ThisWorkbook.Sheets("Sheet1").Cells(1, 1)
S = ""

For i = 1 To 256
S = S + "aap,"
Next

Call SetValidationList(R, S)
End Sub

 
Reply With Quote
 
 
 
 
Héctor Miguel
Guest
Posts: n/a
 
      21st Sep 2008
hi, Bart !

AFAIK there is a constraint of ~255 characters (commas included) for a list-entry in DV ref-edit box (even by code)
your code does not fail, but any characters exceeding that limit, they are NOT (really) being assigned to "the list"

also, DV lists assigned to ranges, supports ~32,767 elements/cells/...

hth,
hector.

__ OP __
> I use VBA to impose data validation to a certain cell. Below is a simple example.
> This works fine and a drop down list is displayed as expected.
> When I save the workbook and open it again Excel complains with the well known "...unreadable content...." message.
> There seems to be a limit to length of the validation list that is not applied when imposing the data validation list by VBA
> but is applied when Excel (re)opens the book. Anyone any suggestions, ideas?
> I am currently deleting all validation lists when the workbook is closed but that is hardly an ideal situation.
>
> Private Sub SetValidationList(ByVal R As Range, ByVal List As String)
> R.Validation.Delete
> With R.Validation
> .Add Type:=xlValidateList, _
> AlertStyle:=xlValidAlertStop, _
> Formula1:=List
> .InCellDropdown = True
> End With
> End Sub
>
> Private Sub Workbook_Open()
> Dim R As Range
> Dim i As Integer
> Dim S As String
> Set R = ThisWorkbook.Sheets("Sheet1").Cells(1, 1)
> S = ""
> For i = 1 To 256
> S = S + "aap,"
> Next
> Call SetValidationList(R, S)
> End Sub



 
Reply With Quote
 
BartM
Guest
Posts: n/a
 
      22nd Sep 2008
Hi Hector,

thanks for your help here. I was not "really" aware of the 255 char limit
(although one clearly hits it when setting up a validation list through the
normal Excel interface as I found out). I am not sure I understand what you
mean by "not really being assigned". In my VBA code I assign a rather long
(>>255) validaton list. By handling "SheetChange" events I catch the user
making a selection and I/the user can use every element of this large list,
exactly like I intended. It is only when I save the workbook and reopen it
that Excel complains.

Any thoughts?

Best,

Bart

"Héctor Miguel" wrote:

> hi, Bart !
>
> AFAIK there is a constraint of ~255 characters (commas included) for a list-entry in DV ref-edit box (even by code)
> your code does not fail, but any characters exceeding that limit, they are NOT (really) being assigned to "the list"
>
> also, DV lists assigned to ranges, supports ~32,767 elements/cells/...
>
> hth,
> hector.
>
> __ OP __
> > I use VBA to impose data validation to a certain cell. Below is a simple example.
> > This works fine and a drop down list is displayed as expected.
> > When I save the workbook and open it again Excel complains with the well known "...unreadable content...." message.
> > There seems to be a limit to length of the validation list that is not applied when imposing the data validation list by VBA
> > but is applied when Excel (re)opens the book. Anyone any suggestions, ideas?
> > I am currently deleting all validation lists when the workbook is closed but that is hardly an ideal situation.
> >
> > Private Sub SetValidationList(ByVal R As Range, ByVal List As String)
> > R.Validation.Delete
> > With R.Validation
> > .Add Type:=xlValidateList, _
> > AlertStyle:=xlValidAlertStop, _
> > Formula1:=List
> > .InCellDropdown = True
> > End With
> > End Sub
> >
> > Private Sub Workbook_Open()
> > Dim R As Range
> > Dim i As Integer
> > Dim S As String
> > Set R = ThisWorkbook.Sheets("Sheet1").Cells(1, 1)
> > S = ""
> > For i = 1 To 256
> > S = S + "aap,"
> > Next
> > Call SetValidationList(R, S)
> > End Sub

>
>
>

 
Reply With Quote
 
Héctor Miguel
Guest
Posts: n/a
 
      23rd Sep 2008
hi, Bart !

> ... I was not "really" aware of the 255 char limit
> (although one clearly hits it when setting up a validation list through the normal Excel interface as I found out).
> I am not sure I understand what you mean by "not really being assigned".
> In my VBA code I assign a rather long (>>255) validaton list.
> By handling "SheetChange" events I catch the user making a selection
> and I/the user can use every element of this large list, exactly like I intended.
> It is only when I save the workbook and reopen it that Excel complains.


AFAIK, versions prior to 2003 does really complain when trying to set a >> 255 characters validation-list (even by code)
also, some versions won't let you "quit" the application :-((

hth,
hector.


 
Reply With Quote
 
New Member
Join Date: Jul 2009
Posts: 2
 
      1st Mar 2011
I appreciate that this is an older post now, but I came across this problem whilst generating a VBA routine that responded to user events using Excel 2007. The premise being that the selection of certain value using one data validation list would lead to the creation of a second data validation list.

I used VBA to construct the data validation list, but got the unreadable content alert.

Further research indicated that this is an issue with the XML format used in 2007, where 255 character strings effectively corrupt the XML coding. I was able to recover the corrupt templates by editing the XML used in the workbook, but then created an On Close event to remove these derived data validations.

As a result I could use data validation lists of more than 255 characters 'between saves'.
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to limit validation list André Microsoft Excel Worksheet Functions 3 20th Nov 2010 04:52 PM
limit on the delimited list for Data Validation. Aleksandra Microsoft Excel Programming 2 29th Jan 2008 08:47 PM
Data validation list limit? =?Utf-8?B?YW5keTYy?= Microsoft Excel Worksheet Functions 3 24th Mar 2007 05:55 PM
Row limit in data validation drop down list? CAToso Microsoft Excel Misc 0 6th Oct 2004 08:25 PM
Row limit in data validation drop down list? CAToso Microsoft Excel Misc 3 6th Oct 2004 08:13 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:35 AM.