Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1600to1604
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Hilfe bei schleife

Hilfe bei schleife
16.01.2018 15:01:05
Johann
Hallo Liebe Forumgemeinde,
hat jemand eine Ahnung wie ich die Hidden schleife auf die Sheets Januar
bis Dezember umsetzten kann?
Mein Code welcher bereits von tollen mitgliedern verbessert wurde hängt
leider immer noch bei diesem Problem.
Sub Kalender_erstellen()
Dim tag As Long
Dim Monat As Integer
Dim jahr As Integer
Dim ersterTag As Date
Dim letzterTag As Date
Dim zeile As Long
Dim spalte As Long
jahr = 2018
Application.ScreenUpdating = False
For Monat = 1 To 12
spalte = 5
With Sheets(Format(DateSerial(jahr, Monat, 1), "MMMM"))
With .Range("A2:AM99")
.ClearContents
.Interior.ColorIndex = xlNone
.EntireColumn.Hidden = False
End With
With .Range("E1:AJ1")
.ClearContents
.Interior.ColorIndex = xlNone
End With
zeile = 1
ersterTag = CDate("01." & Monat & "." & jahr)
letzterTag = DateSerial(Year(ersterTag), Month(ersterTag) + 1, 0)
.Cells(zeile, spalte) = ersterTag
For tag = ersterTag To letzterTag
.Cells(zeile, spalte) = tag
If Weekday(tag, vbMonday) 

2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Hilfe bei schleife
16.01.2018 15:15:04
Sepp
Hallo Johann,
Sub Kalender_erstellen()
Dim tag As Long
Dim Monat As Integer
Dim jahr As Integer
Dim ersterTag As Date
Dim letzterTag As Date
Dim zeile As Long
Dim spalte As Long
jahr = 2018
Application.ScreenUpdating = False
For Monat = 1 To 12
  spalte = 5
  With Sheets(Format(DateSerial(jahr, Monat, 1), "MMMM"))
    With .Range("A2:AM99")
      .ClearContents
      .Interior.ColorIndex = xlNone
      .EntireColumn.Hidden = False
    End With
    With .Range("E1:AJ1")
      .ClearContents
      .Interior.ColorIndex = xlNone
    End With
    zeile = 1
    ersterTag = CDate("01." & Monat & "." & jahr)
    letzterTag = DateSerial(Year(ersterTag), Month(ersterTag) + 1, 0)
    .Cells(zeile, spalte) = ersterTag
    For tag = ersterTag To letzterTag
      .Cells(zeile, spalte) = tag
      If Weekday(tag, vbMonday) < 6 Then
        With .Columns(spalte)
          .Interior.ColorIndex = xlNone
          .Font.ColorIndex = xlAutomatic
          .ColumnWidth = 6.71
        End With
      ElseIf Weekday(tag, vbMonday) = 6 Then
        With .Columns(spalte)
          .Interior.ColorIndex = 48
          .Font.Color = vbWhite
          .ColumnWidth = 4.69
        End With
      ElseIf Weekday(tag, vbMonday) = 7 Then
        With .Columns(spalte)
          .Interior.ColorIndex = 56
          .Font.Color = vbWhite
          .ColumnWidth = 4.69
        End With
      End If
      Select Case tag
        Case DateSerial(Year(tag), 1, 1) 'Neujahr
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
        Case DateSerial(Year(tag), 1, 6) 'Hl. drei Könige
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case Ostern(Year(tag)) - 2 'Karfreitag
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case Ostern(Year(tag)) 'Ostersonntag
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case Ostern(Year(tag)) + 1 'Ostermontag
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case DateSerial(Year(tag), 5, 1) 'Maifeiertag
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case Ostern(Year(tag)) + 39 'Christi Himmelfahrt
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case Ostern(Year(tag)) + 49 'Pfingstsonntag
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case Ostern(Year(tag)) + 50 'Pfingstmontag
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case Ostern(Year(tag)) + 60 'Fronleichnam
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case DateSerial(Year(tag), 8, 15) 'Maria Himmelfahrt
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case DateSerial(Year(tag), 10, 3) 'Tag der D. Einheit
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case DateSerial(Year(tag), 11, 1) 'Allerheiligen
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case DateSerial(Year(tag), 12, 24) 'Heiliger Abend
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case DateSerial(Year(tag), 12, 25) '1. Weihnachtstag
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case DateSerial(Year(tag), 12, 26) '2. Weihnachtstag
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
        Case DateSerial(Year(tag), 12, 31) 'Sylvester
          With .Columns(spalte)
            .Interior.ColorIndex = 56
            .Font.Color = vbWhite
            .ColumnWidth = 4.69
          End With
          
      End Select
      spalte = spalte + 1
    Next tag
    For spalte = spalte To 36
      .Columns(spalte).Hidden = .Cells(1, spalte).Value = ""
    Next
    .Columns(spalte).NumberFormat = "DD DDD"
    .Rows(1).NumberFormat = "DD DDD"
  End With
Next Monat
Application.ScreenUpdating = True
End Sub

Gruß Sepp

Anzeige
AW: Hilfe bei schleife
16.01.2018 15:30:39
Johann
Besten Dank Sepp,
Hab dein Code 1 zu 1 übernommen und Datei gekrasht :)
Irgendwas mit spalte ging nicht.
Also geändert auf
For s = 33 To 36
.Columns(s).Hidden = .Cells(1, s).Value = ""
Next s
Jetzt läuft es genau wie gewollt.
Klasse Arbeit! Danke!

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige