excel - 对象工作表的 VBA 范围失败
问题描述
我在用 *** 表示的行上收到一系列对象工作表失败错误。我无法弄清楚,因为如果我在收到错误消息后单步执行代码,它就不会再次出错。有什么看起来不对吗?
Sub BuildMonthCalender()
Dim wkb As Workbook, shift_lines As Worksheet, month_lines As Worksheet, inputs As Worksheet, schedule As Worksheet
Dim d As Integer, w As Integer, last_row As Double, shift_line As Double, shifts As Double, p As Double, cRow As Double, cCol As Double
Dim counter As Double, cell_value As String
Set wkb = Excel.Workbooks("Call Center Headcount Model.xlsm")
Set schedule = wkb.Worksheets("Schedule")
Set shift_lines = ThisWorkbook.Worksheets("Shift Lines")
Set month_lines = ThisWorkbook.Worksheets("Month Lines")
Set inputs = wkb.Worksheets("Inputs")
schedule.Range("A1:K100000").Clear
last_row = month_lines.Range("A" & Rows.Count).End(xlUp).Row
shift_line = 3
shifts = 3
cRow = 0
cCol = 2
p = 1
'For shift_line = 3 To last_row
With month_lines
Do
If month_lines.Cells(shift_line, 1).Value <> "" Then
For shifts = shift_line To month_lines.Cells(shift_line, 1).CurrentRegion.Rows.Count + shift_line
cell_value = month_lines.Cells(shifts, 1).Value
If cell_value = "" Then
Exit For
End If
schedule.Cells(cRow + month_lines.Cells(shifts, 9).Value, cCol + month_lines.Cells(shifts, 8).Value) = month_lines.Cells(shifts, 7).Value
*****schedule.Range(Cells(p, 1), Cells(p + 5, 1)) = month_lines.Cells(shifts, 3).Value**
schedule.Range(Cells(p, 2), Cells(p + 5, 2)) = month_lines.Cells(shifts, 10).Value
Next shifts
cRow = cRow + 10
p = p + 10
End If
shift_line = .Cells(shift_line, 1).End(xlDown).Row + 3
Loop Until shift_line > last_row
End With
p = 0
For p = 1 To last_row
With schedule.Range(Cells(p, 3), Cells(p + 5, 9))
.Borders.LineStyle = xlContinuous
.HorizontalAlignment = xlCenter
End With
p = p + 9
Next p
MsgBox "Complete!"
End Sub
解决方案
推荐阅读
- asp.net-core - 将 SelectTagHelper 绑定到枚举,对 SelectList 使用 Display(Name)(但保留字符串值而不是 int)
- c - 指向指针成员 Struct 的指针
- html - 自定义复选框,更改 :hover 和 :checked。不工作
- javascript - 如何在 ReactJS 中添加图标
- c# - 在 Asp.net C# 中将带有数据(网格视图)和图像的 html 页面导出为 excel
- python - 带有 Tensorboard 投影仪的 UMAP
- android - Flutter- dart http 库 ClientException
- python - 如何在 django 中为上下文对象执行分页?
- django - Django 和 Jbrowse
- c++ - 用户输入获取枚举值