0

我有一个带有两种颜色文本的电子表格,通常在相同的单元格中。我想运行一个宏,它只从它出现的每个单元格中删除黑色文本。

4

2 回答 2

1

如果您不想使用宏,为什么不使用“查找和选择”工具。转到“替换”。选择“选项”。选择“格式”并选择字体颜色或单元格颜色选项。选择您想要摆脱的颜色,将“替换为”框留空,然后单击“全部替换”

于 2012-12-20T14:38:11.093 回答
0

这应该适合你:

Sub ForEachCharacterTextColor()
Dim wbk As Workbook
Dim i As Integer
Set wbk = ThisWorkbook
Set ws = wbk.Sheets(1)

Dim cell As Range

Cells.Select
Selection.NumberFormat = "@"
Range("A1").Select

On Error GoTo MyExitSub

    With ws
        For Each cell In ws.Range("A1:E2000").Cells
            'cell.Value = "'" & cell.Value
            For i = 1 To Len(cell)
                If cell.Characters(i, 1).Font.Color = RGB(0, 0, 0) Then
                    If Len(cell) > 0 Then
                        cell.Characters(i, 1).Delete
                    End If
                    If Len(cell) > 0 Then
                        i = i - 1
                    End If
                End If
            Next i
        Next cell
    End With


MyExitSub:
    If Err.Number > 0 Then
     MsgBox "Some of your cells are numbers formatted as text. You need to convert them to text completely."
     End
    End If
End Sub

祝你好运。- 只要excel不认为您的任何单元格都是数字,它就会起作用。

于 2012-08-20T21:52:58.553 回答