HERBERS Excel-Forum - das Archiv
Gültigket abfragen
SteffenS

Guten morgen,
wie kann ich abfragen ob eine Zelle eine Gültigkeit hat?
Mit
Range("L24").Validation= True
geht es leider nicht.
Danke Euch
Steffen Schmerler

AW: Gültigket abfragen
Tino

Hallo,
Du kannst es mal so versuchen.
Dim boValidation As Boolean
On Error Resume Next
boValidation = Range("L24").Validation.Type > 0
On Error GoTo 0
If boValidation Then
MsgBox "Zelle hat eine Gültigkeitsprüfung"
Else
MsgBox "Zelle hat keine Gültigkeitsprüfung"
End If
Gruß Tino
prüfe besser ob >=0 weil es 0 auch gibt.
Tino

Hallo,
Dim boValidation As Boolean
On Error Resume Next
boValidation = Range("L24").Validation.Type >= 0
On Error GoTo 0
If boValidation Then
MsgBox "Zelle hat eine Gültigkeitsprüfung"
Else
MsgBox "Zelle hat keine Gültigkeitsprüfung"
End If
Gruß Tino
das Funktioniert nicht
SteffenS

Es kommt immer False raus.
Woran kann das liegen?
Danke
Steffen
AW: das Funktioniert nicht
Nepumuk

Hallo,
versuch es mal so:
Public Function Validation_Exist(objCell As Range) As Boolean
    On Error Resume Next
    Validation_Exist = Not Intersect(objCell, _
        objCell.Parent.Cells.SpecialCells(xlCellTypeAllValidation)) Is Nothing
    Err.Clear
End Function

Public Sub Test()
    If Validation_Exist(Tabelle1.Cells(1, 1)) Then
        MsgBox "Zelle enthält eine Gültigkeitsprüfung"
    Else
        MsgBox "Zelle enthält keine Gültigkeitsprüfung"
    End If
End Sub

Gruß
Nepumuk
hier ein Beispiel, bei mir geht es.
Tino
bei mir gehts jetzt ausch
SteffenS

Hatte in meiner Schleife vergessen den Wert wieder zurückzu setzen
'alte Gültigkeit löschen
AJ.Cells(j, k).Validation.Delete
'Abfrage Gültigkeit
boValidation = False
On Error Resume Next
boValidation = VJ.Cells(i, k).Validation.Type >= 0
On Error GoTo 0
'neue Gültigkeit setzen
If boValidation = True Then AJ.Cells(j, k).Validation.Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:=xlBetween, Formula1:="=$G$204:$G$234"
End If
Danke nochmal an Alle :-)
VG
Steffen