如果满足条件,则从一张纸上复制选定的数据并粘贴到选定范围的其他纸张上

我有两张纸(Sheet1)=纸张(“Jan”)和Sheet2 =纸张(“Feb”)我只想从范围b5:b81从纸张(“Jan”)复制到纸张(“Feb”)如果满足范围AN5:AN81的条件。

我使用这个代码,但不工作

Sub CopyRows() Dim Rng As Range Dim Rng2 As Range Dim Cl As Range Dim str As String Dim RowUpdCrnt As Long Set Rng = Sheets("Jan").UsedRange 'the range to search ie the used range Set Rng2 = Sheets("Jan").Range("B") str = "WRK." 'string to look for Sheets("Feb").Range("B5:B81").Value = "" RowUpdCrnt = 5 ' In my test data, the "Yes"s are in column AN. This For-Each only selects column AN. ' I assume all your "Yes"s are in a single column. Replace "B" by the appropriate ' column letter for your data. For Each Cl In Rng.Columns("AN").Rows If Cl.Text = str Then 'if the cell contains the correct value copy it to next empty row on sheet 2 & delete the row Cl.cell(2, 5).Copy Sheets("Feb").Cells(RowUpdCrnt, 1) RowUpdCrnt = RowUpdCrnt + 1 End If Next Cl End Sub