2017-04-04 51 views
-1

我在Excel中有一个名为“RFQ_selector”的3列表。第二列包含是/否。VBA筛选器表和副本

  1. 我需要一个宏,它将只对第2列中包含“是”的行进行过滤。
  2. 然后宏应该将包含yes的行的每个单元格复制到同一张纸上的新位置。将它们粘贴在单元格F25开始的列表中

我受困了,有人可以帮忙吗? 感谢

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

由于StackOverflow不是免费的代码编写服务,因此您需要显示代码以获得任何帮助。 –

+1

感谢您的建议,我的代码现在在消息中 – gekko2670

回答

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