如果特定列中有任何空白文本,我有一个宏会突出显示一行。此宏用于突出显示用户需要关注的区域。我希望能够通过单击相同的宏按钮在进行更改后取消突出显示这些行。
我该怎么做呢?
这是当前的宏:
Sub Macro13()
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = 2
LastRow = .Cells(.Rows.Count, "M").End(xlUp).Row
For Lrow = LastRow To Firstrow Step -1
With .Cells(Lrow, "M")
If .Value = "" Then
.EntireRow.Interior.ColorIndex = 3
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub
我的想法是,在宏的开头,检查是否有任何行以红色突出显示。如果是这样,运行一个遍历所有列的新循环,删除单元格突出显示,然后在该循环完成后,跳出宏。不过,这很丑陋并且充满了错误。
Sub Macro13() 'Checks for Incorrect Countries
With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
With ActiveSheet
.Select
ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView
.DisplayPageBreaks = False
Firstrow = 2
LastRow = .Cells(.Rows.Count, "M").End(xlUp).Row
FirstrowA = 2
LastRowA = .Cells(.Rows.Count, "M").End(xlUp).Row
For Lrow = LastRow To Firstrow Step -1
With .Cells(Lrow, "M")
If .EntireRow.Interior.ColorIndex = 3 Then
For LrowA = LastRowA To FirstrowA Step -1
.EntireRow.Interior.ColorIndex = xlColorIndexNone
Next LrowA
End
Exit Sub
End If
If .Value = "" Then
.EntireRow.Interior.ColorIndex = 3
End If
End With
Next Lrow
End With
ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With
End Sub