ich habe eine Zeile mit dem Datum vom 1.1.2005 bis 31.12.2005. Jetzt möchte ich mit VBA in der darüberliegenden Zeile immer die Zellen vom ersten bis zum letzten Tag eines jeden Monats verbinden. Wie kann ich das machen?
Gruß Thomas
Sub Makro2()
Range("B4").Select
Selection.FormulaR1C1 = "=DAY(DATE(YEAR(R[1]C),MONTH(R[1]C)+1,1)-1)"
i = ActiveCell.Value + 1
For x = 3 To i
Cells(5, x) = Cells(5, x - 1) + 1
Next x
With Range(Cells(4, 2), Cells(4, i)) 'Zeile 9 Spalte B bis Monatsletzter
.MergeCells = True 'verbinden
.Value = Format(Range("b5"), "MMMM") 'Monat
.HorizontalAlignment = xlCenter 'Schrift zentrieren
End With
End Sub
Sub Makro2()
If ActiveCell.Row <> 4 Then
MsgBox "Falsche Zeile aktiv", , "Abbruch"
Exit Sub
End If
acol = ActiveCell.Column
bcol = ActiveCell.Column
ActiveCell.FormulaR1C1 = "=DAY(DATE(YEAR(R[1]C),MONTH(R[1]C)+1,1)-1)"
i = ActiveCell.Value + 1
For x = acol To acol + i
Cells(5, x) = Cells(5, x - 1) + 1
Next x
With Range(Cells(4, bcol), Cells(4, bcol + i))
.MergeCells = True
.Value = Format(Cells(5, bcol), "MMMM")
.HorizontalAlignment = xlCenter
End With
End Sub
Sub Monateverbinden()
acol = ActiveCell.Column + 1
arow = ActiveCell.Row
ActiveCell.FormulaR1C1 = "=DAY(DATE(YEAR(R[1]C),MONTH(R[1]C)+1,1)-1)"
i = ActiveCell.Value + 1
For x = acol To acol + i - 3
Cells(arow + 1, x) = Cells(arow + 1, x - 1) + 1
Next x
With Range(Cells(arow, acol - 1), Cells(arow, acol + i - 3))
.MergeCells = True
.Value = Format(Cells(arow + 1, acol), "MMMM YY")
.HorizontalAlignment = xlCenter
End With
With Range(Cells(arow + 1, acol - 1), Cells(arow + 1, acol + i - 3))
.NumberFormat = "dd/"
.ColumnWidth = 4
End With
End Sub