Data Extraction Macro

Curben

Board Regular
Joined
Aug 18, 2011
Messages
65
I need help cleaning up and repeating some VBA.

The below code opens up one of my users spreadsheets, extracts the "Customer" data, sorts the remaining lines, then closes and saves the users spreadheet before sorting and cleaning the master spreadsheets.

I am looking for help with two things.
A) cleaning up this code, this is 90% a recorded macro and I am sure it can be condensed
B) Repeating this procedure with all of the files in the folder.

Any help will be appreciated.
Regards.

Code:
Sub Macro2()
'
' Macro2 Macro
'
'Find first empty row
Range("A1").End(xlDown).Offset(1, 0).Select
'Import Data
'Open User Form
    Workbooks.Open Filename:= _
        "C:\FD User Entry Forms\FDEntryU1AM.xlsm"
'Open the rows grouping
    ActiveSheet.Outline.ShowLevels RowLevels:=2
'Filter to Customer
    ActiveSheet.Range("$A$2:$Q$400").AutoFilter Field:=15, Criteria1:="Customer"
'Copy all remaining rows
    Range("A3").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
'Paste into Master File
    Windows("Customer Bin Master.xlsm").Activate
    ActiveSheet.Paste
'Clear data
    Windows("FDEntryU1AM.xlsm").Activate
    Application.CutCopyMode = False
    Selection.ClearContents
'Remove Filtering
    ActiveSheet.Range("$A$2:$Q$400").AutoFilter Field:=15
'Sort remaining data to remove blank rows
    ActiveWorkbook.Worksheets("Bin Entry").AutoFilter.Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Bin Entry").AutoFilter.Sort.SortFields.Add Key:= _
        Range("A2:A400"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets("Bin Entry").AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
'Close grouping of rows
    ActiveSheet.Outline.ShowLevels RowLevels:=1
'Close User File
    ActiveWindow.Close SaveChanges:=True
    Selection.End(xlDown).Select
'End Data Import
'Sort Master File
    Range("A1").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range("A1:Q400").Select
    ActiveWorkbook.Worksheets("Customer Vendor Bin").Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Customer Vendor Bin").Sort.SortFields.Add Key:= _
        Range("A2:A400"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortNormal
    ActiveWorkbook.Worksheets("Customer Vendor Bin").Sort.SortFields.Add Key:= _
        Range("C2:C400"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortNormal
    ActiveWorkbook.Worksheets("Customer Vendor Bin").Sort.SortFields.Add Key:= _
        Range("E2:E247"), SortOn:=xlSortOnValues, Order:=xlAscending, DataOption _
        :=xlSortTextAsNumbers
    With ActiveWorkbook.Worksheets("Customer Vendor Bin").Sort
    'Range of entire spreadsheet
        .SetRange Range("A1:Q2000")
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
    End With
End Sub
 

Excel Facts

Create a Pivot Table on a Map
If your data has zip codes, postal codes, or city names, select the data and use Insert, 3D Map. (Found to right of chart icons).

Forum statistics

Threads
1,224,607
Messages
6,179,871
Members
452,948
Latest member
UsmanAli786

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