我正在尝试根据单元格颜色将行复制到 excel 中的其他工作表。 我的代码如下。但这不是复制。我做错了什么?
'
Sub Button1_Click()
a = Worksheets("Sheet1").Cells(Rows.Count, 1).End(xlUp).Row
For i = 2 To a
If Worksheets("Sheet1").Cells(i, 2).Interior.Color = RGB(255, 0, 0) Then
Worksheets("Sheet1").Rows(i).Copy
Worksheets("Sheet2").Activate
b = Worksheets("Sheet2").Cells(Rows.Count, 1).End(xlUp).Row
Worksheets("Sheet2").Cells(b + 1, 1).Select
ActiveSheet.Paste
Worksheets("Sheet1").Activate
End If
Next
Application.CutCopyMode = False
ThisWorkbook.Worksheets("Sheet1").Cells(1, 1).Select
End Sub
'
从你之前的问题来看,我猜你正在使用条件格式。
在这种情况下,您必须使用Range.DisplayFormat.Interior.Color
.
If Worksheets("Sheet1").Cells(i, 2).DisplayFormat.Interior.Color = RGB(255, 0, 0) Then
请注意,您还应该避免Select
和Activate
。