複雑な質問があります... データを .csv ファイルからワークシート (インポートされたデータ) にインポートしました。別のワークシート (インポート関数) で、ボタンをマクロとして使用して、特定のデータを除外します。フィルターは、セル A2、セル B2、セル C2 に入力されたデータに依存します (これらのフィルターは、Excel のユーザーによって入力されます)。これらのフィルターがワークシート (インポートされたデータ) の行と一致する場合、これらの値を別のワークシートに貼り付ける必要があります。どうすればいいですか?A2、B2、および C2 のこれらのフィルターは、他のワークシートの A、B、C と一致します。
事前にThx..
返信で、私は今コードを持っています:
Sub FilterButton()
If MsgBox("Are you sure the fields 'Collection' and 'System' are filled in?", vbInformation + vbYesNo, "Sort function") = vbYes Then
'If vbYesNo = Yes Then'
Dim ws1, ws2, ws3 As Worksheet
Dim filter1, filter2, filter3 As String
Dim lrow As Double
Set ws1 = ThisWorkbook.Sheets("Import") 'this contains the filters
Set ws2 = ThisWorkbook.Sheets("Imported Data") 'this contains the text file
Set ws3 = ThisWorkbook.Sheets("Test") ' this is the destination
With ws1
filter1 = "=" & .Range("A2").Value
filter2 = "=" & .Range("B2").Value
filter3 = "=" & .Range("C2").Value
End With
With ws2
lrow = .Range("A" & .Rows.Count).End(xlUp).Row
With .Range("A1:G" & lrow)
.AutoFilter Field:=1, Criteria1:=filter1
.AutoFilter Field:=2, Criteria1:=filter2
.AutoFilter Field:=3, Criteria1:=filter3
.Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow.Copy _
ws3.Cells(.Range("A" & .Rows.Count).End(xlUp).Row + 1, 1)
End With
.AutoFilterMode = False
End With
End If
End Sub
私の検索条件 (ws1 の A2,B2,C2 は ws2(A2,B2,C2) の検索条件と一致しますが、ws3 には貼り付けられませんか?