|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
Sub 按钮1_Click()
Application.ScreenUpdating = False
If [c2] = 12 Then
d = 31
Else
d = Day(CDate([c1] & "-" & [c2] + 1 & "-1") - 1)
End If
[m3:aq4].ClearContents
[m3:aq4].Interior.ColorIndex = xlNone
For j = 1 To d
Cells(3, j + 12) = j
Cells(4, j + 12) = Format(CDate([c1] & "-" & [c2] & "-" & j), "AAA")
If Cells(4, j + 12) = "周日" Then Cells(4, j + 12).Interior.ColorIndex = 3
Next j
ActiveSheet.UsedRange.Offset(4, 11).ClearContents
ActiveSheet.UsedRange.Offset(4, 11).Interior.ColorIndex = xlNone
arr = ActiveSheet.UsedRange
y = 12 + d
For j = 5 To UBound(arr)
If Len(arr(j, 2)) > 0 Then
For i = 3 To 9
For k = 1 To Val(arr(j, i))
l1:
x = WorksheetFunction.RandBetween(13, y)
If Len(arr(j, x)) = 0 And arr(4, x) <> "周日" Then
Z = WorksheetFunction.Max(13, x - 2)
w = WorksheetFunction.Min(y, x + 2)
n = 0
For k1 = Z To w
If arr(j, k1) = arr(4, i) Then
n = n + 1
End If
Next k1
If n >= 2 Then GoTo l1
arr(j, x) = arr(4, i)
Cells(j, x) = arr(4, i)
Cells(j, x).Interior.ColorIndex = arr(4, i) + 2
Else
GoTo l1
End If
Next k
Next i
End If
Next j
ActiveSheet.UsedRange = arr
Application.ScreenUpdating = True
End Sub
|
评分
-
1
查看全部评分
-
|