'Copy only filtered data to a new workbook with vba
I am trying to filter data in an excel worksheet, copy the filtered data only and move it to a new workbook. However, when I complete that step, I still have access to the other options. For example, I filter for Cars in column A but when I copy to the new workbook, I see Cars and the other options which I did not filter for like Buses and bikes and I can select them as well. Can you look at my code and see what i could change to copy and paste only car data in the workbook? Note, I have tried the special type cells code and it did not work. The coding is below:
Sub getdata()
Dim newWB As Workbook
Dim folderPath As String, filename As String, fullPath As String
FolderPath = Config.Range("CurrentQuarterFolderPath").Value
fileName = "mycars.xlsx"
FullPath = folderPath & Application.PathSeparator & fileName
Workbooks.Add
Set newWB = ActiveWorkbook
On Error Resume Next
Tests_trans.ShowAllData
Tests_trans.Range("$A$2:$O$2").AutoFilter Field:=1, Criterial:="=*Cars*", _
Operator:=xlAnd
Worksheets("Allvehicles").Cells(1,1).SpecialCells(xlCellTypeVisible).Select
Tests_trans.Copy After:=newWB.Worksheets(newWB.Sheets.Count)
Please help me
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|