Excel found unreadable content - Data Validation

后端 未结 5 1222
长发绾君心
长发绾君心 2020-12-17 01:49

I have some combo boxes that I populate on opening of the workbook - the source of the data comes from a database.

I populate my combo boxes using data validation wi

相关标签:
5条回答
  • 2020-12-17 02:05

    It seems that you are right with the string length of Validation formula1 parameter. My suggestion for you is as follows (additional information are placed as comments within the code):

    'Split your list into array, or if data are Array before you _
    create List variable you could combine some of earlier steps _
    of your code
    
        List = Split(List, ",")
    'paste your list into hidden sheet as of A1 direction bottom, _
    we need to transpose our Array to do so
        Sheets("hidden").Range("a1").Resize(UBound(List) + 1, 1) = Application.Transpose(List)
    
     With Selection.Validation
        .Delete
        'here we need to change definition of formula
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, _
        Formula1:="=Hidden!A1:A" & UBound(List) + 1
        .IgnoreBlank = False
        .InCellDropdown = True
        .ShowInput = True
        .ShowError = True
      End With
    
    0 讨论(0)
  • 2020-12-17 02:08

    Just ran into this issue (limit on data validation formula length at workbook opening), and like the OP wouldn't want to go with auxiliary ranges.

    My workaround is to delete the validations in the Workbook_BeforeSave handler.

    My use case is to always refresh the data from external sources, so it is a viable option to always delete all imported data and validations before saving the workbook.

    0 讨论(0)
  • 2020-12-17 02:14

    I've solved this issue by deleting my validation in WorkbookBeforeSave event. However, I'm using C#

    0 讨论(0)
  • 2020-12-17 02:15

    I've manipulated validation lists before in some of my Excel projects. When you set validation to Allow:List, you can set your data Source to be a workbook-level named range. In this example, I've defined a named range "listrange":

    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
            xlBetween, Formula1:="=listrange"
        .IgnoreBlank = True
        .InCellDropdown = True
        .ShowInput = True
        .ShowError = True
    End With
    

    You'll never get an error for that formula string being too long.

    I put all my validation-referenced named ranges in one worksheet, and make it hidden. Then my code manipulates those named ranges, which in turn update the values available from the validation drop-down menus.

    It can be tricky to dynamically update the size of the named ranges while they are being updated, but it's not too hard with VBA, particularly not if you're returning sets from a database, where you can get a record count. The alternative is to go the ActiveX control route, but I like the clean, native look and feel of the data validation drop-downs.

    0 讨论(0)
  • 2020-12-17 02:21

    there is a way around, save the strings you use for your conditional formatting somewhere in the workbook before using it. when you use them, reference them to the range where you saved them and not from the strings. Remember longs string in conditional formatting is what causes it do a function that when closing the workbook wipes out the problematic condition formatting and another function that when opening puts them back on

    Problem solved and it works a treat :)

    0 讨论(0)
提交回复
热议问题