Excel VBA代码不使用F5仅使用F8运行

w46czmvw  于 2023-03-24  发布在  其他
关注(0)|答案(1)|浏览(156)

下面是我的VBA代码,它在使用F8运行时执行,但在使用F5运行时执行。它没有给予任何错误或任何东西,它只是不运行。

Dim LastColumn As Long
Set ws = ActiveSheet
Dim LastRow As Long
LastRow = 0
LastColumn = 0

LastRow = ws.Range("c" & Rows.Count).End(xlUp).Row
LastColumn = ws.Cells(11, ws.Columns.Count).End(xlToLeft).Column
Range(Cells(12, 1), Cells(LastRow, LastColumn)).Select
Selection.SpecialCells(xlCellTypeVisible).Interior.ColorIndex = -4142
delay 60
Range("A1").Select

我试着延迟代码60秒,也许它运行得太快,但也不起作用。任何帮助?

mnemlml8

mnemlml81#

以下是代码的一个版本,其范围限定为工作表级别:

Dim LastColumn As Long
Set ws = ActiveSheet ' you should change this to Worksheets("YourSheetName") to be safer
Dim LastRow As Long
LastRow = 0
LastColumn = 0
With ws
    LastRow = .Range("c" & .Rows.Count).End(xlUp).Row
    LastColumn = .Cells(11, .Columns.Count).End(xlToLeft).Column
    .Range(.Cells(12, 1), .Cells(LastRow, LastColumn)).SpecialCells(xlCellTypeVisible).Interior.ColorIndex = -4142
    delay 60
    .Range("A1").Select
End With

这是假设所有的范围都在同一个Activesheet上。

相关问题