È possibile aumentare il limite di 256 caratteri nelle caselle a discesa di convalida Excel?

StackOverflow https://stackoverflow.com/questions/90365

  •  01-07-2019
  •  | 
  •  

Domanda

Sto creando la convalida in modo dinamico e ho raggiunto il limite di 256 caratteri.La mia convalida è simile a questa:

Level 1, Level 2, Level 3, Level 4.....

Esiste un modo per aggirare il limite di caratteri oltre a puntare a un intervallo?

La validazione è già in fase di produzione in VBA.Aumentare il limite è il modo più semplice per evitare qualsiasi impatto sul funzionamento corrente del foglio.

È stato utile?

Soluzione

Sono abbastanza sicuro che non sia possibile aggirare il limite di 256 caratteri, Joel Spolsky spiega perché qui: http://www.joelonsoftware.com/printerFriendly/articles/fog0000000319.html.

Potresti tuttavia utilizzare VBA per avvicinarti alla replica della funzionalità della convalida integrata codificando l'evento Worksheet_Change.Ecco un mock up per darti l'idea.Probabilmente vorrai rifattorizzarlo per memorizzare nella cache i ValidValues, gestire le modifiche agli intervalli di celle, ecc...

Private Sub Worksheet_Change(ByVal Target As Range)
Dim ValidationRange As Excel.Range
Dim ValidValues(1 To 100) As String
Dim Index As Integer
Dim Valid As Boolean
Dim Msg As String
Dim WhatToDo As VbMsgBoxResult

    'Initialise ValidationRange
    Set ValidationRange = Sheet1.Range("A:A")

    ' Check if change is in a cell we need to validate
    If Not Intersect(Target, ValidationRange) Is Nothing Then

        ' Populate ValidValues array
        For Index = 1 To 100
            ValidValues(Index) = "Level " & Index
        Next

        ' do the validation, permit blank values
        If IsEmpty(Target) Then
            Valid = True
        Else
            Valid = False
            For Index = 1 To 100
                If Target.Value = ValidValues(Index) Then
                    ' found match to valid value
                    Valid = True
                    Exit For
                End If
            Next
        End If

        If Not Valid Then

            Target.Select

            ' tell user value isn't valid
            Msg = _
                "The value you entered is not valid" & vbCrLf & vbCrLf & _
                "A user has restricted values that can be entered into this cell."

            WhatToDo = MsgBox(Msg, vbRetryCancel + vbCritical, "Microsoft Excel")

            Target.Value = ""

            If WhatToDo = vbRetry Then
                Application.SendKeys "{F2}"
            End If

        End If

    End If

End Sub
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top