我创建了一个宏,以便在进行更改时将一个单元格更改为黄色(顶级宏)。现在我想要创建一个代码,这样我就可以创建一个按钮来单击以删除所有用顶部宏创建的黄色。
我找到了下面的代码,它确实将手动高亮显示的单元格从黄色转回白色,而不是从Top的单元格变成黄色的。
以下是我使用的格式:
用于在更改时创建黄色颜色:
'Highlight cells yellow if change occurs
Private Sub Workbook_SheetChange(ByVal Sh As Object, ByVal Target As Range)
If Target.Cells.Count > 1 Then Exit Sub
Target.Interior.ColorIndex = 6
End Sub删除黄色高亮显示的(只适用于手动更改-而不是宏)
Sub RemoveYellowFillColor()
Dim cell As Range
'Optimize Code
Application.ScreenUpdating = False
'Ensure Cell Range Is Selected
If TypeName(Selection) <> "Range" Then
MsgBox ("A2:Z1000")
Exit Sub
End If
'Loop Through Each Cell
For Each cell In Selection.Cells
If cell.Interior.Color = vbYellow Then
cell.Interior.Color = xlNone
End If
Next
End Sub发布于 2020-09-26 16:12:20
这是我回答的第一篇:
正如注释中所指出的,从Target.Interior.ColorIndex = 6更改为Workbook_SheetChange中的Target.Interior.ColorIndex = vbYellow。
然后按以下方式更新宏:
Sub RemoveYellowFillColor()
Dim ws As Worksheet, cell As Range
'Optimize Code
Application.ScreenUpdating = False
'Loop Through Each Cell
For Each ws In Worksheets
For Each cell In ws.UsedRange.Cells
If cell.Interior.Color = vbYellow Then cell.Interior.Color = xlNone
Next cell
Next ws
Application.ScreenUpdating = True
End Sub运行此宏后,将从工作簿中所有工作表上的所有单元格中删除vbYellow填充。
https://stackoverflow.com/questions/64071760
复制相似问题