循环遍历工作簿中所有表单中的所有单元格,如果为红色,则更改格式

我正在尝试将所有单元格中的所有红色文本更改为黑色,以显示Excel工作簿的所有表单。 我正在使用以下内容:

Sub RedToBlack() Dim Current As Worksheet For Each Current In Worksheets For Each cell In Current If cell.Font.ColorIndex = 3 Then cell.Font.ColorIndex = 0 End If Next Next End Sub 

我知道这是错误的,但是想知道我在做什么。 谁能提供build议? 感谢您的帮助,我对此很新。

你有什么可能会做这项工作。 但是,这将是非常低效的。 更好的方法是使用这样的查找和replace。

 'set the next find to find the red With Application.FindFormat.Font .ColorIndex = 3 End With 'set the next find to replace with black With Application.ReplaceFormat.Font .ColorIndex = 1 End With 'Do the actual replacing For Each aSheet In ActiveWorkbook.Worksheets aSheet.Activate Cells.Replace What:="", Replacement:="", LookAt:=xlPart, SearchOrder:= _ xlByRows, MatchCase:=False, SearchFormat:=True, ReplaceFormat:=True Next aSheet 

这对于整个工作簿的所有表单中的所有单元格都是这样。 您也可以通过正常查找并replace窗口然后按下选项button来完成此操作。

 Sub change_color() For Each sht In ActiveWorkbook.Sheets Set rng = sht.UsedRange For Each cell In rng If cell.Font.ColorIndex = 3 Then cell.Font.ColorIndex = 0 End If Next cell Next sht End Sub