我现在有这个代码:
Dim holrange1, holrange2 As Range
Dim holrange As Variant
Set holrange1 = Sheets("Resource Leave Plan").Range(holday & "4:" & holday & "103")
Set holrange2 = Sheets("Holidays").Range("B3:B202")
Set holrange = Nothing
Set holrange = Range(holrange1.Address & "," & holrange2.Address)
Worksheets("Schedule").Unprotect Password:="dfss"
Worksheets("Schedule").Cells(Target.Row, 7).Value = WorksheetFunction.WorkDay(strdt, noofdays, holrange)其中strdt和noofday是整数,并且已经定义。我收到错误消息“Unable to get the WorkDay property of WorksheetFunction class”。
我想这是因为我在两个不同的工作表上设置了变量holrange的范围。
我怎么才能让它工作呢?
发布于 2015-09-11 03:28:41
我在附近找到了这个工作。由于可以使用最后一个参数作为数组,因此我构造了一个数组,其中包含两个区域中的单元格值。
我确实尝试过使用Union函数将两个范围连接成一个范围,但是我不能正常工作(因为我不熟悉使用Union)。
Dim r1, r2 As Range
Dim rCell As Range
Dim x As Integer
Set r1 = Sheets("Sheet1").Range("A1:A1")
Set r2 = Sheets("Sheet2").Range("A1:A1")
ReDim r(r1.Count + r2.Count)
x = 0
For Each rCell In r1.Cells
r(x) = rCell.Value
x = x + 1
Next rCell
For Each rCell In r2.Cells
r(x) = rCell.Value
x = x + 1
Next rCell
MsgBox WorksheetFunction.WorkDay(Now(), 1, r)https://stackoverflow.com/questions/32493080
复制相似问题