excel 如何复制红色字体的单元格,而不是行?

xiozqbni  于 2023-04-22  发布在  其他
关注(0)|答案(2)|浏览(244)

我正在使用一个教程。它的工作时,所有的文本在一行有红色字体。
我需要:
1.选择红色字体的单元格,并复制那些只不是整个行,并把它复制到新工作表上的相同位置的单元格。
1.将行列A中的代码值复制到新工作表中。

当前代码:

Sub CopyColouredFontTransactions()

    Dim TransIDField As Range
    Dim TransIDCell As Range
    Dim ATransWS As Worksheet
    Dim HTransWS As Worksheet
    Dim x As Long
    
    Set ATransWS = Worksheets("All Transactions")
    Set TransIDField = ATransWS.Range("A2", ATransWS.Range("A2").End(xlDown))
    Set HTransWS = Worksheets("Highlighted Transactions")
    
    For Each TransIDCell In TransIDField
    
        If TransIDCell.Font.Color = RGB(255, 0, 0) Then
           
            TransIDCell.Resize(1, 10).Copy Destination:= _
                HTransWS.Range("A1").Offset(HTransWS.Rows.Count - 1, 0).End(xlUp).Offset(1, 0)
               
        End If
    
    Next TransIDCell
    
    HTransWS.Columns.AutoFit

End Sub
enxuqcxy

enxuqcxy1#

就像这样:

For Each TransIDCell In TransIDField
    If TransIDCell.Column = 1 Or TransIDCell.Font.Color = vbRed Then
        TransIDCell.Copy HTransWS.Range(TransIDCell.Address)
    End If
Next TransIDCell
8cdiaqws

8cdiaqws2#

我实际上是vba的新手,我有点想尝试解决它。我得到了你想要的输出,但在执行方法上有点偏离。请随意评论。

Public Sub ClearNorm()
Dim xlw As Worksheet
Dim range_1 As Range

  For Each range_1 In Range("B2:D4")
      If range_1.Font.Color <> vbRed Then
        range_1.ClearContents
   End If
  Next range_1
  Range("A1").CurrentRegion.Copy Sheets(2).Range("A1")
Sheets(2).Activate

End Sub

相关问题