Excel VBA - Bedingungen
Aus SAP-Wiki
Zur Navigation springenZur Suche springen
If und Case
If Bedingung Then Anweisung Anweisung Else elseAnweisung elseAnweisung endif
Sub ZelleLeer() If ActiveCell.Value = "" Then MsgBox "Zelle ist leer", vbInformation Else MsgBox "Zelle ist gefüllt!", vbInformation End If End Sub
Sub DatenTypInZelleFeststellen() If IsEmpty(ActiveCell.Value) Then MsgBox "Zelle ist leer", vbInformation Else If IsNumeric(ActiveCell) Then MsgBox "Zelle enthält eine Zahl", vbInformation Else MsgBox "Zelle enthält einen Text", vbInformation End If End If End Sub
Select Case Ausdruck Case Ausdrucksliste-n Anweisungen-n … Case Else elseAnw End Select
Sub ExcelVersionFeststellen() MsgBox Application.Version Select Case Left(Application.Version, 1) Case "5" MsgBox "Excel 5" Case "7" MsgBox "Excel 7/95" Case "8" MsgBox "Excel 8/97" Case "9" MsgBox "Excel 2000" Case "1" Select Case Left(Application.Version, 2) Case 10 MsgBox "Excel 2002" Case 11 MsgBox "Excel 2003" Case 12 MsgBox "Excel 2007" Case 13 MsgBox "Excel 2010" End Select Case Else MsgBox "Unbekannte Version von Excel", vbInformation End Select End Sub