Galapagos15
Board Regular
- Joined
- Sep 16, 2015
- Messages
- 100
I wrote VBA to copy and paste rows of data that match a specific company name from another file which uses a filter to select the needed data. This works but I need the criteria coding to be changed so I don't have to manually list the company name (i.e. ABC Company) but instead will be the Company Name which the user selected from a drop down box in cell A1 in my working file.
I know this line needs recoded but don't know how ActiveSheet.Range("$a$2:$bd$15446").AutoFilter Field:=2, Criteria1:= _"ABC Company"
Sub MacroFSPMedical()
Dim ReportWbk As Workbook 'workbook with report data
Dim Report As String 'name of file with report data
Set TempBook = ThisWorkbook
Application.FileDialog(msoFileDialogFilePicker).Show
Report = Application.FileDialog(msoFileDialogFilePicker).SelectedItems(1)
Set ReportWbk = Workbooks.Open(Report)
Sheets("Medical").Select
Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("$a$2:$bd$15446").AutoFilter Field:=2, Criteria1:= _
"ABC Company"
ActiveSheet.UsedRange.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
TempBook.Sheets("FSP Medical Data").Range("a3").PasteSpecial xlPasteValues
End Sub
Thanks in advance!
I know this line needs recoded but don't know how ActiveSheet.Range("$a$2:$bd$15446").AutoFilter Field:=2, Criteria1:= _"ABC Company"
Sub MacroFSPMedical()
Dim ReportWbk As Workbook 'workbook with report data
Dim Report As String 'name of file with report data
Set TempBook = ThisWorkbook
Application.FileDialog(msoFileDialogFilePicker).Show
Report = Application.FileDialog(msoFileDialogFilePicker).SelectedItems(1)
Set ReportWbk = Workbooks.Open(Report)
Sheets("Medical").Select
Rows("1:1").Select
Selection.AutoFilter
ActiveSheet.Range("$a$2:$bd$15446").AutoFilter Field:=2, Criteria1:= _
"ABC Company"
ActiveSheet.UsedRange.Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
TempBook.Sheets("FSP Medical Data").Range("a3").PasteSpecial xlPasteValues
End Sub
Thanks in advance!