Streamline Macro Code for filtering, copying, and pasting

jcihak

New Member
Joined
Jun 6, 2018
Messages
8
Hi there, below is the code I have in the excel file. Basically what it does it starts with one tab full of data, creates 3 new tabs, and then filter/copy/paste information from the original data set to each of the 3 new tabs based upon different attributes. It also adds a new "date" column to the original data set.

I am pretty new to VBA and made this macro with mostly online searches and the record function. I'm curious to see if there are more advanced ways write this code so the file runs faster, doesn't take up as much space, and doesn't constantly crash


Thank you!




Code:
[FONT='inherit']Public Sub sing_off_formatting()[/FONT]
<code style="font-family: "Courier New", courier, monospace; margin: 0px 2px; padding: 15px; border: 0px; background-color: transparent; border-radius: 2px; word-break: normal; display: block; font-size: 1em; line-height: 16px; overflow: auto;">    Selection.CurrentRegion.Select
        Selection.Columns.AutoFit
        Selection.Rows.AutoFit

        'Creates tabs for each of the desired reports
        Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Prepared Screens"
        Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Senior Reviewed"
        Sheets.Add(After:=Sheets(Sheets.Count)).Name = "Manager Reviewed"

        'Creates a column that only has a date for reference
        Sheets("sing off analysis macro").Activate
        Columns("O:O").Select
        Selection.Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
        Range("O1").Select
        ActiveCell.FormulaR1C1 = "Prepared Date"
        Range("O2").Select
        ActiveCell.FormulaR1C1 = "=RIGHT(RC[1],9)"
        Range("O2").Select
        Selection.AutoFill Destination:=Range("O2:O999")
        Columns("O:O").Select
        Selection.NumberFormat = "m/d/yyyy"

        'Creates report with screens that are prepared and not reviewed and highlights screens prepared last month
        Sheets("sing off analysis macro").Activate
        Sheets("sing off analysis macro").Cells.Select
        ActiveSheet.Range("$A$1:$U$352").AutoFilter Field:=3, Criteria1:="Prepared"
        Selection.SpecialCells(xlCellTypeVisible).Select
        Selection.Copy
        Sheets("Prepared Screens").Activate
        ActiveSheet.Paste
        Selection.Columns.AutoFit
        Selection.Rows.AutoFit


        'creates report with screens that are reviewed by only the senior and highlights screens prepared last month
        Sheets("sing off analysis macro").Activate
        Range("C1").Select
        ActiveSheet.ShowAllData
        ActiveSheet.Range("$A$1:$T$352").AutoFilter Field:=13, Criteria1:= _
        "XXXXXXX, Timothy"
        Selection.SpecialCells(xlCellTypeVisible).Select
        Selection.Copy
        Sheets("Senior Reviewed").Activate
        ActiveSheet.Paste
        Selection.Columns.AutoFit
        Selection.Rows.AutoFit
        Range("E1").Select
        Selection.AutoFilter
        ActiveSheet.Range("$A$1:$T$7").AutoFilter Field:=7, Criteria1:="="

        'creates report with screens that are reviewed by only the manager and highlights screens prepared last month
        Sheets("sing off analysis macro").Activate
        Range("C1").Select
        ActiveSheet.ShowAllData
        ActiveSheet.Range("$A$1:$T$352").AutoFilter Field:=13, Criteria1:= _
        "XXXXX, Scott"
        Selection.SpecialCells(xlCellTypeVisible).Select
        Selection.Copy
        Sheets("Manager Reviewed").Activate
        ActiveSheet.Paste
        Selection.Columns.AutoFit
        Selection.Rows.AutoFit
        Range("E1").Select
        Selection.AutoFilter
        ActiveSheet.Range("$A$1:$T$7").AutoFilter Field:=5, Criteria1:="="

    End Sub</code>
 
Last edited by a moderator:

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,652
Messages
5,838,597
Members
430,557
Latest member
MK15

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
Top