我的代码循环遍历大量数据,复制包含B列中短语Flowing
的任何行,并将该行粘贴到另一个工作表中。代码是:
Sub HighlightFlowingIntervals()
Worksheets("3901").Activate
Dim i As Long
Dim cell As Range
Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("3901")
Dim ws2 As Worksheet: Set ws2 = ThisWorkbook.Sheets("Sheet2")
For i = 6 To ws1.Range("C17300").End(xlUp).Row
If ws1.Cells(i, "B").Value = "Flowing" Then ws1.Rows(i).Copy ws2.Rows(ws2.Cells(ws2.Rows.Count, 2).End(xlUp).Row + 1)
Next i
End Sub
我现在想要使用相同的循环结构,但不是复制和粘贴每一行,只需突出显示通过“If..Then”条件的每一行。我知道如何突出使用宏录制器,但除非必须,否则不想这样做。我只是不确定如何在循环中实现突出显示。
答案 0 :(得分:1)
只需使用条件格式。
答案 1 :(得分:0)
您需要拆分then
行
Sub Button1_Click()
Dim i As Long
Dim cell As Range
Dim ws1 As Worksheet: Set ws1 = ThisWorkbook.Sheets("3901")
Dim ws2 As Worksheet: Set ws2 = ThisWorkbook.Sheets("Sheet2")
With ws1
For i = 6 To .Cells(.Rows.Count, "C").End(xlUp).Row
If .Cells(i, "B").Value = "Flowing" Then
.Rows(i).Copy ws2.Rows(ws2.Cells(ws2.Rows.Count, 2).End(xlUp).Row + 1)
.Range(.Cells(i, "A"), .Cells(i, "D")).Interior.Color = vbYellow
End If
Next i
End With
End Sub