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:

Some videos you may like

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.

Watch MrExcel Video

Forum statistics

Threads
1,109,360
Messages
5,528,236
Members
409,809
Latest member
VICKRAM

This Week's Hot Topics

  • Change military grades into rank
    Afternoon all Need help with formula that will change military rank (i.e. 1, 2, 3 into Amn, A1C, SrA). Running IF formula that does not work...
  • VBA COUNTIF SOLUTION
    Hi The following are the errors spread across the several columns from E to Q ie. 13 columns across several sheets with more than 500 rows per...
  • INSERT ROW WITH SPECIFIS TEXT IN A COLUMN
    Hi All! How can identify that that the row to be inserted has to be inserted before 1st row with specific text in column F. If I record the...
  • Auto-Create a monthly Sign in sheet for preschool students
    The image below is what each page looks like. Above is space for the "Child Name" "Month" "Class" School days are obviously Monday-Friday but...
  • VBA vlookup multiple results
    Hi folks, Hopefully someone out there can help. I have a list to vlookup which works (ish). the lookup only picks up the first instance of the...
  • Extract values for earliest/latest times
    I am trying to put together a formula to get the earliest start time, the latest end time from column A for each person in Column B-F without the...
Top