2017-04-04 93 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