【发布时间】:2020-06-30 17:21:05
【问题描述】:
我有一系列复选框单元格,该范围上方的几行会自动列出相应月份的月份日期和工作日。当单击按钮时,我正在尝试用“/”填充所有框,这些框位于周末或本月之外。
我已经为完全相同的标准设置了条件格式,以使复选框单元格的背景变为灰色,并且所述逻辑完美运行。我使用“+”代替 OR,WEEKDAY 中的第二个参数对应于起始工作日(1 = 星期日)。已经尝试在 VBA 函数中使用 1,但每个单元格仍然被填充。
=OR(WEEKDAY(B$4,1)>6,WEEKDAY(B$4,1)<2)+NOT(MONTH(B$4)=MONTH($B$3)) 'Works perfect
我的“Set refcell.Column ...”行有什么问题?它给了我一个“错误数量的参数或无效的属性分配”编译错误。
修改后的代码:
Private Sub CommandButton1_Click()
Dim rng As Range, cell As Range, refcell As Range
CommandButton1.AutoSize = False
CommandButton1.AutoSize = True
CommandButton1.Height = 21.75
CommandButton1.Left = 218.25
CommandButton1.Width = 96
With ThisWorkbook.ActiveSheet
Set rng = .Range("B7:AF16")
For Each cell In rng
Set refcell = .Cells(4, cell.Column)
If Weekday(refcell, vbSunday) > 6 Or Weekday(refcell, vbSunday) < 2 Or (Not (Month(refcell) = Month(B3))) Then
'Above logic seems to just fill every cell
cell.Value = "/"
End If
Next cell
End With
End Sub
【问题讨论】:
-
Range.column是read only -
^ 和
Range.Row一样。也许如果您笼统地解释您要做什么,我们可以提供更好的帮助。