0

多くの場合、同じセルに 2 色のテキストを含むスプレッドシートがあります。表示されている各セルから黒いテキストのみを削除するマクロを実行したいと思います。

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 に答える