首页 > 解决方案 > 如何在 Excel 中的多个选项卡中将特定单元格颜色更改为无填充?

问题描述

我目前正在尝试将工作簿中具有特定颜色的多个工作表的单元格更改为无填充。这是我在下面使用的代码。任何人都可以帮忙吗?

Sub YellowFillToNoFill()
        'RGB(246, 244, 150) Yellow Colour To change to no Fill

       'PURPOSE: Change any cell with a Yellow fill color to a No fill color

        Dim cell As Range

       'Optimize Code
        Application.ScreenUpdating = False

        'Ensure Cell Range Is Selected
        If TypeName(Selection) <> "Range" Then
        MsgBox "Please select some cells before running"
        Exit Sub
        End If

       'Loop Through Each Cell
        For Each cell In ActiveSheet.UsedRange 'Can also use Range("C1,C2" etc.) instead of 
        'Selection.Cells' or 'ActiveSheet.UsedRange'
          If cell.Interior.Color = RGB(246, 244, 150) Then
          cell.Interior.Color = xlNone
          End If
        Next
End Sub

标签: excelvba

解决方案


要重置该值,请使用 Usecell.Interior.ColorIndex = xlNone

Color定义显示的颜色。它是一个long包含颜色 RGB 值的值。

ColorIndex是预定义颜色表(在 Excel 中选择颜色时看到的颜色表)的索引。特殊值xlNone(-4142) 删除任何颜色设置。


推荐阅读