AW: VBA Zeile überprüfen, MsgBox anzeigen
10.05.2007 15:22:00
Erich
Hallo Peter,
das gehört wohl kaum in diesen Thread - jetzt gehts doch um ein ganz neues Thema.
Warum soll der Benutzer unbedingt eine ganze Zeile markieren? Für diese Anwendung reicht es aus,
wenn die Zeile eindeutig klar ist, also nicht Zellen aus mehreren Zeilen markiert sind.
Ein Klick in eine Zelle mit Datum in Spalte A würde m. E. ausreichen.
Cells(lngZ, 6) <> 0 trifft übrigens auch zu, wenn in der Zelle ein Text steht.
Probier mal diese beiden Versionen:
Option Explicit
Private Sub Konto_Click()
Dim lngZ As Long, strM As String
If Selection.Areas.Count > 1 Or Selection.Rows.Count > 1 Then
strM = "Sie haben Zellen in mehr als einer Zeile markiert!"
Else
lngZ = ActiveCell.Row
If Not IsDate(Cells(lngZ, 1)) Then
strM = "In Spalte A der ausgewählten Zeile steht kein Datum!"
Else
If Cells(lngZ, 6) 0 Or Cells(lngZ, 7) 0 Then strM = "DA/Allgemeines Lewa"
If Cells(lngZ, 14) 0 Or Cells(lngZ, 15) 0 Then _
strM = IIf(strM > "", strM & vbLf, "") & "DA/Allgemeines Euro"
If Cells(lngZ, 18) 0 Or Cells(lngZ, 19) 0 Then _
strM = IIf(strM > "", strM & vbLf, "") & "DA/Kontokorrent Lewa"
If Cells(lngZ, 22) 0 Or Cells(lngZ, 23) 0 Then _
strM = IIf(strM > "", strM & vbLf, "") & "DA/Kontokorrent Euro"
End If
End If
If strM > "" Then MsgBox strM
End Sub
Private Sub Konto_Click2()
Dim lngZ As Long, strM As String
'SpeedUp (True) ' 1 Or Selection.Rows.Count > 1 Then
strM = "Sie haben Zellen in mehr als einer Zeile markiert!"
ElseIf ActiveCell.Column > 1 Then
strM = "Bitte markieren Sie per Klick" & vbLf & vbLf _
& "links auf die Zeilennummer " & ActiveCell.Row
ElseIf Selection.Address ActiveCell.EntireRow.Address Then
MsgBox "Sie haben nicht die ganze Zeile markiert!"
ElseIf Not IsDate(ActiveCell) Then
strM = "In Spalte A der ausgewählten Zeile steht kein Datum!"
Else
lngZ = ActiveCell.Row
If Cells(lngZ, 6) 0 Or Cells(lngZ, 7) 0 Then strM = "DA/Allgemeines Lewa"
If Cells(lngZ, 14) 0 Or Cells(lngZ, 15) 0 Then _
strM = IIf(strM > "", strM & vbLf, "") & "DA/Allgemeines Euro"
If Cells(lngZ, 18) 0 Or Cells(lngZ, 19) 0 Then _
strM = IIf(strM > "", strM & vbLf, "") & "DA/Kontokorrent Lewa"
If Cells(lngZ, 22) 0 Or Cells(lngZ, 23) 0 Then _
strM = IIf(strM > "", strM & vbLf, "") & "DA/Kontokorrent Euro"
End If
If strM > "" Then MsgBox strM
'SpeedUp (False)
End Sub
Rückmeldung wäre nett! - Grüße von Erich aus Kamp-Lintfort