Sub test()
Dim i%, BegCol%, HolDay(22) As Date, tmpR As Range
[c1] = "24 Jan 2005"
[c4] = DateAdd("d", 28, [c1])
BegCol = [d4].Column
Range(Cells(6, BegCol), Cells(40, BegCol + 28)).Interior.ColorIndex = xlNone
Range(Cells(41, BegCol), Cells(41, BegCol + 28)).ClearContents
Range(Cells(4, BegCol), Cells(4, BegCol + 28)).MergeCells = False
For i = 1 To 22
HolDay(i) = Sheets("PH").Cells(1 + i, 1)
If HolDay(i) > [c4] Then Exit For
Next
For BegCol = 1 To i - 1
If HolDay(BegCol) >= [c1] And HolDay(BegCol) <= [c4] Then
Cells(41, [d4].Column + (HolDay(BegCol) - [c1])) = Sheets("PH").Cells(1 + BegCol, 3).Value
End If
Next
[c4] = DateSerial(Year([c1]), Month([c1]) + 1, 0)
i = [c4] - [c1]
[d4] = [c1]
[d4].HorizontalAlignment = xlCenter
[d4].NumberFormatLocal = "mmm"
BegCol = [d4].Column
Range([d4], Cells(4, BegCol + i)).Merge
Cells(4, BegCol + i + 1) = [c4] + 1
Cells(4, BegCol + i + 1).HorizontalAlignment = xlCenter
Cells(4, BegCol + i + 1).NumberFormat = "mmm"
Set tmpR = Range(Cells(4, BegCol + i + 1), Cells(4, BegCol + 28))
tmpR.Merge
With tmpR.Borders(xlEdgeLeft)
.LineStyle = xlContinuous
.ColorIndex = 5
End With
[d5] = DatePart("ww", [c1])
For i = 1 To 3
Cells(5, BegCol + i * 7) = [d5] + i
Next
For ii% = 1 To 28
i = BegCol + ii% - 1
If ii% Mod 7 = 0 Or Len(Cells(41, i)) > 0 Then
Range(Cells(6, i), Cells(40, i)).Interior.ColorIndex = 20
End If
Next
End Sub
出现这样的提示是因为合并时,其它单元格有内容,初始化时把它们清了就行了.这是上面程序的第7句,在其下加一句.
Range(Cells(4, BegCol), Cells(4, BegCol + 28)).MergeCells = False
增加的语句是:
Range(Cells(4, BegCol), Cells(4, BegCol + 28)).ClearContents
[此贴子已经被作者于2005-6-22 10:03:26编辑过] |