从一张纸过滤数据并粘贴到另一张纸上

时间:2018-03-27 02:59:51

标签: vba excel-vba excel

我正在尝试从sheet1的一列过滤数据,并将完整的数据集放入带有标题的sheet2。粘贴为值最好。 尝试过的代码,但它没有按预期工作。

Option Explicit
Function FilterAndCopy(rng As Range, Choice As String)

    Dim FiltRng As Range
     'Clear Contents to show just new search data
    Worksheets("Sheet2").Cells.ClearContents
     'Set the column to filter (In This Case 1 or A)
     'Change as required
    rng.AutoFilter Field:=23, Criteria1:=Choice
    On Error Resume Next
    Set FiltRng = rng.SpecialCells(xlCellTypeVisible).EntireRow
    On Error GoTo 0

    'Copy Data across to sheet 2
    FiltRng.Copy Worksheets("Sheet1").Range("A1")
    'Display Data
    Worksheets("Sheet2").Select
    Range("A1").Select
    Set FiltRng = Nothing
End Function

Sub formshow()
'Show Search Form
UserForm1.Show
End Sub

是否可以使用sheet2固定单元格的值来提供过滤条件?

0 个答案:

没有答案