Select file then apply filter

2022

Board Regular
Joined
Jun 5, 2022
Messages
74
Office Version
  1. 2016
Platform
  1. Windows
Hi, I'd like to open a file but then apply a filter to the data in a tab (let's say Sheet1) then type in certain criteria in the filter in column D, after which I'd like the Sub to import the data displayed when the filter is applied.

I've got a Sub which enables me to select a file then import data from that file without applying any filters.

Buut is there a way to modify this so that it applies a filter to row 4 then allows a user to search for a word eg 'Gold' in the filter in column D, after which it copies all the data that appears on the page when that word is applied in the filter?

This is the Sub I have, so far:

VBA Code:
Sub ImportTest12()



Dim fd As FileDialog


Dim filewaschosen As Boolean


Dim Report As Workbook


Dim iWB As Workbook


Set Report = ActiveWorkbook


Set fd = Application.FileDialog(msoFileDialogOpen)


fd.Filters.Clear


'fd.Filters.Add "xlsx files", "*.xlsx"


fd.Filters.Add "Custom Excel Files", "*.xlsx, *.xlsm, *.xls"


fd.AllowMultiSelect = False


fd.InitialFileName = Environ("UserProfile") & "\Downloads\"


'filewaschosen = fd.Show


fd.Execute


If fd.Show <> -1 Then
   MsgBox "You didn't select a file?"
   Exit Sub
End If
fd.Execute



lastrow = Cells(Rows.Count, "A").End(xlUp).Row


Range("A2:G" & lastrow).Copy


Report.Activate


ACV.Visible = True


ACV.Activate


Range("A2:G" & lastrow).PasteSpecial


End Sub
 

Excel Facts

Do you hate GETPIVOTDATA?
Prevent GETPIVOTDATA. Select inside a PivotTable. In the Analyze tab of the ribbon, open the dropown next to Options and turn it off

Forum statistics

Threads
1,213,561
Messages
6,114,315
Members
448,564
Latest member
ED38

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top