1.4k Aufrufe
Gefragt in Tabellenkalkulation von nok106 Einsteiger_in (71 Punkte)
Hallo Leute,
Ich brauche eure Hilfe.
Wenn beim folgendem Code eine leere Zelle, in der abzufragenden Spalte erscheint, stopp das Makro.
Was habe ich da falsch gemacht?

Sub Monat()
Dim Datum As Date
Dim Zeile As Long
Dim MediName As String
Application.ScreenUpdating = False
Zeile = 2
Do Until IsEmpty(Cells(Zeile, 6))
Datum = Cells(Zeile, 6)
With Range(Cells(Zeile, 1), Cells(Zeile, 6))
.Interior.ColorIndex = xlNone
If Month(Day(Datum) & "." & Month(Datum) & "." & Year(Date)) = Month(Now) Then
.Interior.ColorIndex = 40
End If
End With
Zeile = Zeile + 1
Loop
Application.ScreenUpdating = True
End Sub

Einstweilen herzlichen Dank an alle, die sich für mich bemühen.

MfG
Odje

5 Antworten

0 Punkte
Beantwortet von hajo_zi Experte (9.1k Punkte)
Hallo Odje,

zu wenig Infiormationen. Wir sehen Deine Datei nicht. Bei mir läuft es durch.

Gruß Hajo
0 Punkte
Beantwortet von nok106 Einsteiger_in (71 Punkte)
Hallo Hajo,

Excel-Version 2007

In Zeile 1 bis 25 stehenNamen der Medikamente.
In Spalte "F" stehen die Bestelldaten(Datum),
fehlt in einer Zeile ein Datum bleibt, wie erwähnt, das dort Makro stehen.

Gruß
Odje
0 Punkte
Beantwortet von hajo_zi Experte (9.1k Punkte)
Hallo Odje,

Ich baue keine Datei nach, die Zeit hat schon jemand investiert. Ein Link zur Datei wäre nicht schlecht.
Bei mir stehrt was in F2 und F4 und es läuft durch F3 ist leer. Dein gewünschterv Fall, laut Beitrag 1

Gruß Hajo
0 Punkte
Beantwortet von hajo_zi Experte (9.1k Punkte)
Hallo Odje,
teste dieses Makro.

Option Explicit

Sub Monat()
Dim Datum As Date
Dim Zeile As Long
Dim MediName As String
Application.ScreenUpdating = False
Zeile = 2
Do Until IsEmpty(Cells(Zeile, 6))
If IsError(Cells(Zeile, 6)) = False Then
If Cells(Zeile, 6) <> "" Then
If IsDate(Cells(Zeile, 6)) Then
Datum = Cells(Zeile, 6)
With Range(Cells(Zeile, 1), Cells(Zeile, 6))
.Interior.ColorIndex = xlNone
If Month(Day(Datum) & "." & Month(Datum) & "." & Year(Date)) = Month(Now) Then
.Interior.ColorIndex = 40
End If
End With
End If
End If
End If
Zeile = Zeile + 1
Loop
Application.ScreenUpdating = True
End Sub

Gruß Hajo
0 Punkte
Beantwortet von rainberg Profi (14.9k Punkte)
Hallo Odje,

Alternative:

Option Explicit

Sub test()
Dim rngC As Range
For Each rngC In Range("F2:F" & Cells(Rows.Count, 6).End(xlUp).Row)
If Month(Day(rngC) & "." & Month(rngC) & "." & Year(rngC)) = Month(Now) Then
Range("A" & rngC.Row & ":F" & rngC.Row).Interior.ColorIndex = 40
End If
Next
End Sub


Gruß
Rainer
...