|
本帖最后由 alxixi520 于 2015-12-26 17:40 编辑
请教:下面代码如何将数据改为由D3,D4开始?并且将“六,日”对应列指定不同颜色。
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer
Dim yy As Integer, mm As Integer
Dim rng As Range
Set rng = Target.Cells(1, 1)
If rng.Address = "$AB$1" And VBA.IsDate(rng) Then
Me.Rows(3).ClearContents
Me.Rows(4).ClearContents
yy = Year(rng)
mm = Month(rng)
For i = 1 To VBA.DateSerial(yy, mm + 1, 1) - VBA.DateSerial(yy, mm, 1)
Me.Cells(3, i) = i
Me.Cells(4, i) = Application.WorksheetFunction.Choose(VBA.Weekday(DateSerial(yy, mm, i)), _
"日", "一", "二", "三", "四", "五", "六")
Next
End If
End Sub
Private Sub Worksheet_Change(ByVal Target As Range)
Dim i As Integer
Dim yy As Integer, mm As Integer
Application.EnableEvents = False
If Target.Address = "$AB$1" And VBA.IsDate(Target) Then
Me.Rows(3).ClearContents
Me.Rows(4).Clear
yy = Year(Target)
mm = Month(Target)
For i = 1 To VBA.DateSerial(yy, mm + 1, 1) - VBA.DateSerial(yy, mm, 1)
Me.Cells(3, i + 3) = i
Me.Cells(4, i + 3) = Application.WorksheetFunction.Choose(VBA.Weekday(DateSerial(yy, mm, i)), _
"日", "一", "二", "三", "四", "五", "六")
If Cells(4, i + 3) = "六" Then Cells(4, i + 3).Interior.Color = 65535
If Cells(4, i + 3) = "日" Then Cells(4, i + 3).Interior.Color = 225
Next
End If
Application.EnableEvents = True
End Sub
|
-
|