在单元格中剪切指定的字体颜色文本,然后粘贴到下一个单元格/列

时间:2019-02-08 11:50:23

标签: excel vba

我有一个在一个单元格中具有多个字体颜色文本的excel文件。例如,一个单元具有黑色和蓝色字体颜色数据。我需要剪切蓝色字体颜色数据并粘贴到下一个单元格/列。

我有一个宏,它只删除指定的字体颜色数据。

Sub deletecolor_v2()
  Dim rng As Range, c As Range
  Dim s As String, sTemp As String
  Dim aCol
  Dim p As Long, i As Long, k As Long, L As Long

  Set rng = Range("A1:A10")
  For Each c In rng
    s = c.Value
    L = Len(s)
    If L > 0 Then
      k = 0
      sTemp = vbNullString
      ReDim aCol(1 To L, 1 To 2)
      For p = 1 To L
        If c.Characters(p, 1).Font.Color <> vbRed Then
          k = k + 1
          aCol(k, 1) = c.Characters(p, 1).Font.Color
          aCol(k, 2) = c.Characters(p, 1).Font.Underline
          sTemp = sTemp & Mid(s, p, 1)
        End If
      Next p
      c.Value = sTemp
      For p = 1 To k
        c.Characters(p, 1).Font.Color = aCol(p, 1)
        c.Characters(p, 1).Font.Underline = aCol(p, 2)
      Next p
    End If
  Next c
End Sub

0 个答案:

没有答案