我在Excel中的Excel中的代码在Excel中的问题,在Excel 97中,但不在Excel 16中

我有一个代码,我已经写在excel 97中的电子表格中工作,但不是在2016年…代码是为了把一个数据表分割成3个部分命名….._ Haz1 .. ._Haz2 …_ Haz3 …..

每列中的每个项目都有checkbox,它们是一个风险评估表,当代码运行时,它应该把所有打勾的项目放在下面的表格中。

我已经创build了一个button,并将macros指向button,所以当你点击button时,它会运行那个特定的macros。

当我点击button时,它会运行下移的代码,好像项目被放到下面的表格中,但是我只是得到了一个粗蓝线和ni表中的项目……

我很困惑,它在以前的Excel 1997工作,但不是在2016年的Excel

Option Explicit Public iHazCount Sub CompileHazards() iHazCount = 0 Application.ScreenUpdating = False Call ClearCompileArea Call FetchHazards(Range("Hazards!Haz1"), -3) Call FetchHazards(Range("Hazards!Haz2"), -4) Call FetchHazards(Range("Hazards!Haz3"), -7) ' set print area ActiveSheet.PageSetup.PrintArea = "$A$1:$Q$" & 80 + iHazCount Application.Goto Reference:=Range("A91"), Scroll:=True Application.ScreenUpdating = True End Sub Sub FetchHazards(rHazList As Range, iDataOffset As Integer) Dim rHazCell As Range Dim iCurrRow As Integer For Each rHazCell In rHazList If rHazCell.Value = True Then ' calculate row postion iCurrRow = 81 + iHazCount ' first add line ' select bottom blank line and copy it down Range("A" & iCurrRow & ":Q" & 82 + iHazCount).Select Selection.Copy Range("A" & iCurrRow + 1).Select ActiveSheet.Paste ' go back to orig blank line and change blue bottom border Range("A" & iCurrRow & ":Q" & iCurrRow).Select Application.CutCopyMode = False With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlThin .ColorIndex = xlAutomatic End With ' copy hazard Range("A" & iCurrRow).Value = rHazCell.Offset(0, iDataOffset).Value ' insert risk formula Range("P" & iCurrRow).Formula = "=IF(N" & iCurrRow & "*O" & iCurrRow & "< 7,""LOW"",IF(N" & iCurrRow & "*O" & iCurrRow & "< 11 ,""MID"",""HIGH""))" ' increment line count iHazCount = iHazCount + 1 End If Next End Sub Sub ClearCompileArea() ' delete all rows below first Rows("83:121").Select Selection.Delete Shift:=xlUp ' clear contents of first row Range("A81:Q81").Select Selection.ClearContents ' reinsert blue bottom border With Selection.Borders(xlEdgeBottom) .LineStyle = xlContinuous .Weight = xlMedium .ColorIndex = 5 End With End Sub