0

依存リスト検証のある2つのセルがあります-最初のセルの値に基づいて2番目のセルのリスト/選択ボックスを取得するためにINDIRECTを使用しています。

私がしなければならないことはもっと複雑で、解決策を見つけるのに苦労しています。

cellAでは、value1が選択されている場合、cellBにはlist1が必要です(これは今すぐ実行できます)が、cellAでvalue2またはvalue3が選択されている場合、cellBにはリスト値ではなく任意の数値が必要です。

基本的に、あるインスタンスではcellBでリストの検証が必要ですが、別のインスタンスでは、数値の検証(任意の数値)が必要です。

誰かがこれを手伝うことができますか?感謝します。

4

1 に答える 1

0

これを自動的に行う唯一の方法は、VBAを使用して正しいタイプの検証を適用することだと思います。

次の例は、そのままでは立ち寄ることができませんが、何をする必要があるかについての手がかりが得られるはずです。このコードは、作業しているシートのワークシートコードモジュールに配置されます。

マクロレコーダを使用して、必要な検証を生成するためのコードを取得できます。

あなたが持っているあなたのコードと式であなたの質問を更新することができれば、私はあなたのニーズにこれをもう少し修正することができるかもしれません。

Private Sub Worksheet_Change(ByVal Target As Range)
' Target is a reference to the Cell(s) that have changed.

    If Target.Address = "$A$1" Then
    ' We only care about this cell (CellA)
        Select Case Target.Value
        Case "needalist"
            ' remove any existing validation and add the list validation to $B$1 (CellB)
            With Sheet1.Range("$B$1").Validation
                .Delete
                .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=$C$1:$C$7" ' Formula1 Can contain a formula
                .IgnoreBlank = True
                .InCellDropdown = True
                .InputTitle = ""
                .ErrorTitle = ""
                .InputMessage = ""
                .ErrorMessage = ""
                .ShowInput = True
                .ShowError = True
            End With
        Case "needanumber"
            ' remove any existing validation and add the number validation to $B$1 (CellB)
            With Sheet1.Range("$B$1").Validation
                .Delete
                .Add Type:=xlValidateWholeNumber, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="1", Formula2:="10" ' Formula1 is min, Formula2 is max
                .IgnoreBlank = True
                .InCellDropdown = True
                .InputTitle = ""
                .ErrorTitle = ""
                .InputMessage = ""
                .ErrorMessage = ""
                .ShowInput = True
                .ShowError = True
            End With
        Case Else
            ' Catch Everything
            Sheet1.Range("$B$1").Validation.Delete
        End Select
    End If

End Sub
于 2013-03-15T00:31:21.560 に答える