我正在尝试将 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
我知道这是错误的,但想说明我正在尝试做什么。任何人都可以提供建议吗?感谢您的帮助,我对此很陌生。
最佳答案
你所拥有的可能会完成这项工作。然而,这将是极其低效的。更好的方法是像这样使用查找和替换。
'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
这适用于整个工作簿的所有工作表中的所有单元格。您也可以通过转到正常的查找和替换窗口然后按选项按钮来执行此操作。
关于vba - 循环遍历工作簿中所有工作表中的所有单元格,如果是红色则更改格式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5820167/