Home VBA Makro Beispiele Datum VBA - Monat ohne Sonntag
VBA - Monat ohne Sonntag PDF Drucken E-Mail
Geschrieben von: Marcus Rose   
Sonntag, 11. Mai 2008 um 22:30 Uhr

Aufgabe war einen Monat mit Datum und Wochentag aufzulisten. Es durfte allerdings kein Sonntag in der Liste erscheinen. Dieses Makro bewältigt das Problem. Wenn das Makro gestartet wird erscheint erst einmal eine Inputbox, welche nach dem Startdatum fragt. Hier gebt Ihr dann zum Beispiel den 01.01.2007 ein. Erst wird für den Monat 1 ein Kalender generiert - danach werden alle Sonntage gelöscht.

 

Tabelle1

 AB
2Montag01.01.2007
3Dienstag02.01.2007
4Mittwoch03.01.2007
5Donnerstag04.01.2007
6Freitag05.01.2007
7Samstag06.01.2007
8Montag08.01.2007
9Dienstag09.01.2007
10Mittwoch10.01.2007
11Donnerstag11.01.2007
12Freitag12.01.2007
13Samstag13.01.2007
14Montag15.01.2007
15Dienstag16.01.2007
16Mittwoch17.01.2007
17Donnerstag18.01.2007
18Freitag19.01.2007
19Samstag20.01.2007
20Montag22.01.2007
21Dienstag23.01.2007
22Mittwoch24.01.2007
23Donnerstag25.01.2007
24Freitag26.01.2007
25Samstag27.01.2007
26Montag29.01.2007
27Dienstag30.01.2007
28Mittwoch31.01.2007

Option Explicit

Sub Wochentage_eintragen()
    Dim i As Integer
    Dim j As Date
    Application.ScreenUpdating = False
    j = InputBox("Anfangsdatum eingeben:")
    Range("A2:B31").ClearContents
    Range("B2") = j
    Range("B2") = Format(Range("B2"), "DD.MM.YYYY")
    Range("A2") = Weekday(Range("B2"))
    Range("A2") = Format(Range("A2"), "DDDD")
    For i = 1 To 31
        Cells(2 + i, 2) = CDate(Cells(i + 1, 2)) + 1
        Cells(2 + i, 2) = Format(Cells(2 + i, 2), "DD.MM.YYYY")
        Cells(2 + i, 1) = Weekday(Cells(2 + i, 2))
        Cells(2 + i, 1) = Format(Cells(2 + i, 1), "DDDD")
    Next
    For i = 33 To 2 Step -1
    If Month(Cells(i, 2)) <> Month(Range("B2")) Then Rows(i).Delete Shift:=xlUp
    If Cells(i, 1) = "Sonntag" Then Rows(i).Delete Shift:=xlUp
    Next
    Application.ScreenUpdating = True
End Sub
 
Copyright © 2012 ms-excel.eu. Alle Rechte vorbehalten.
 

Autoren - Login

Werbung

wichtige Links:
http://ms-excel.eu
Hier habt Ihr eine gute Excel Hilfe
Besucherstatistik
Besucher gesamt: 1.306.262
Besucher heute: 489
Besucher gestern: 2.823
Max. Besucher pro Tag: 3.367
gerade online: 1
max. online: 85
counter Statistiken