我在excel中有一个名为“RFQ_selector”的3列表。第二列包含是/否。
我遇到了困难,请有人帮忙。 感谢
Sub CopyYes()
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
Dim Target As Worksheet
' Change worksheet designations as needed
Set Source = ActiveWorkbook.Worksheets("Trader")
Set Target = ActiveWorkbook.Worksheets("Sheet2")
j = 1 ' Start copying to row 1 in target sheet
For Each c In Source.Range("C8:C22") ' Do 30 rows
If c = "yes" Then
Source.Rows(c.Row).Copy Target.Rows(j)
j = j + 1
End If
Next c
End Sub
答案 0 :(得分:0)
我已修改您的子广告以反映您所需的更改:
- 将每个单元格复制到同一张上的新位置的包含“是”的行的左侧。将它们粘贴在列表中 在单元格F25
它没有过滤,您提供的代码中没有发生过滤,但输出只包含"是"列
Sub CopyYes()
Dim c As Range
Dim j As Integer
Dim Source As Worksheet
'Target worksheet not needed, pasting to source worksheet
' Change worksheet designations as needed
Set Source = ActiveWorkbook.Worksheets("Sheet1")
j = 25 'Start copying to F25
For Each c In Source.Range("B2:B30") 'Change the range here to fit the range in which your data for Yes/No is stored
If c = "Yes" Then 'Verify capitalization here, difference between "Yes" and "yes"
c.Offset(0, -1).Copy Source.Range("F" & j) 'Copy the cell to the left of the Yes/No column and paste on same sheet starting at row F25
j = j + 1
End If
Next c
End Sub