0

当 EXCEL365 中的某个范围被激活时,单元格变为灰色。当子程序完成并退出时,它们保持灰色。我假设一个人想要在退出子程序之前停用范围以使单元格变白。Microsoft 帮助页面中没有很好地处理此主题。有什么建议么?sub 为用户提供了正确的外观,但没有解决问题

Sub TestActivate()

Dim myWkBk As Workbookr code here`
Dim myWkSh As Worksheet
Dim myRange As Range
Set myWkBk = ThisWorkbook
Set myWkSh = myWkBk.Worksheets("Sheet1")
Set myRange = Range("A1:L50")
myRange.Activate

Cells(1, 1).Value = 1
Cells(2, 1).Value = 2

Range("A1:L50").Interior.ColorIndex = -4142

End Sub
4

1 回答 1

0

最好的方法是首先不激活范围:

Sub TestActivate()

Dim myWkBk As Workbook
Dim myRange As Range
Set myWkBk = ThisWorkbook
Set myWkSh = myWkBk.Worksheets("Sheet1")
Set myRange = Range("A1:L50")

With myRange
    .Cells(1, 1).Value = 1
    .Cells(2, 1).Value = 2
End With 'myRange

End Sub

高温高压

于 2020-09-28T00:24:08.080 回答