如何使高级过滤器将一行数据复制到范围?

时间:2019-08-05 08:05:54

标签: excel vba filter

我需要过滤第26列中的数据。有时,过滤后仅会有一行数据。当我使用高级过滤器时,显然无法复制一行。

这是我的代码。我在这里遇到错误C5

.Range(.Cells(2, 26), .Cells(.Rows.count, 26).End(xlUp)).AdvancedFilter Action:=xlFilterCopy, Copytorange:=.Cells(1, .Columns.count), Unique:=True

我是否可以添加条件以检查使用的范围是否为1行,然后以其他方式将该范围复制到 With ws Set rData = .Range(.Cells(1, 1), .Cells(.Rows.count, 26).End(xlUp)) .Columns(.Columns.count).Clear .Range(.Cells(2, 26), .Cells(.Rows.count, 26).End(xlUp)).AdvancedFilter Action:=xlFilterCopy, Copytorange:=.Cells(1, .Columns.count), Unique:=True For Each rfl In .Range(.Cells(1, .Columns.count), .Cells(.Rows.count, .Columns.count).End(xlUp)) vendor = Trim(Left(rfl.Text, 31)) ' MsgBox (vendor) If WksExists(vendor) Then Sheets(vendor).Cells.Clear Else Set wsNew = Sheets.Add wsNew.Move After:=Worksheets(Worksheets.count) wsNew.Name = Trim(vendor) End If rData.AutoFilter Field:=26, Criteria1:=vendor & "*" rData.Copy Destination:=Worksheets(vendor).Cells(1, 1) Worksheets(vendor).Columns.AutoFit Next rfl End With ws.Columns(Columns.count).ClearContents rData.AutoFilter

0 个答案:

没有答案