How to streamline?

sachavez

Active Member
Joined
May 22, 2009
Messages
469
This code takes about 30-seconds to run. I feel like it should take about a second. Is there a more-effective way to do this? Thanks in advance!


VBA Code:
Sub Fcst()
'
    Application.ScreenUpdating = False
   
    Sheets.Add.Name = "2024"
    Sheets.Add.Name = "2023"
    Sheets.Add.Name = "2022"
    Sheets("FCST Report").Move after:=Sheets("FCST")
    Sheets("2022").Move after:=Sheets("FCST Report")
    Sheets("2023").Move after:=Sheets("2022")
    Sheets("2024").Move after:=Sheets("2023")
   
    Sheets("FCST").Select
    Range("A3").Select
    ActiveSheet.Range("$A$3:$BB$5000").AutoFilter Field:=3, Criteria1:="2022"
    Range("A3").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Selection.Copy
    Sheets("2022").Range("A1").PasteSpecial xlPasteValues
   
   
    ActiveSheet.Range("$A$3:$BB$5000").AutoFilter Field:=3, Criteria1:="2023"
    Range("A3").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("2023").Range("A1").PasteSpecial xlPasteValues
   
   
    ActiveSheet.Range("$A$3:$BB$5000").AutoFilter Field:=3, Criteria1:="2024"
    Range("A3").Select
    Range(Selection, Selection.End(xlDown)).Select
    Range(Selection, Selection.End(xlToRight)).Select
    Application.CutCopyMode = False
    Selection.Copy
    Sheets("2024").Range("A1").PasteSpecial xlPasteValues
    ActiveWorkbook.Save
    Range("A3").Select
    ActiveSheet.Range("$A$3:$BB$5000").AutoFilter Field:=3
    'Sheets(Array("2022", "2023", "2024")).Columns.AutoFit
   
    Application.CutCopyMode = False
    Application.ScreenUpdating = True
   
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).
Untested, but will be a starting point
VBA Code:
Sub Fcst()
Dim lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
    Application.ScreenUpdating = False
    Sheets.Add.Name = "2024"
    Sheets.Add.Name = "2023"
    Sheets.Add.Name = "2022"
    Sheets("FCST Report").Move after:=Sheets("FCST")
    Sheets("2022").Move after:=Sheets("FCST Report")
    Sheets("2023").Move after:=Sheets("2022")
    Sheets("2024").Move after:=Sheets("2023")
     With Sheets("FCST")
         .Range("$A$3:$BB" & lr).AutoFilter Field:=3, Criteria1:="2022"
        .UsedRange.Copy Sheets("2022").Range("A1")
        .Range("$A$3:$BB" & lr).AutoFilter Field:=3, Criteria1:="2023"
        .UsedRange.Copy Sheets("2023").Range("A1")
        .Range("$A$3:$BB" & lr).AutoFilter Field:=3, Criteria1:="2024"
        .UsedRange.Copy Sheets("2024").Range("A1")
        .AutoFilter
    End With
    With Sheets(Array("2022", "2023", "2024"))
        With UsedRange
            .Value = .Value
        End With
    End With
    ActiveWorkbook.Save
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Untested, but will be a starting point
VBA Code:
Sub Fcst()
Dim lr As Long
lr = Cells(Rows.Count, "A").End(xlUp).Row
    Application.ScreenUpdating = False
    Sheets.Add.Name = "2024"
    Sheets.Add.Name = "2023"
    Sheets.Add.Name = "2022"
    Sheets("FCST Report").Move after:=Sheets("FCST")
    Sheets("2022").Move after:=Sheets("FCST Report")
    Sheets("2023").Move after:=Sheets("2022")
    Sheets("2024").Move after:=Sheets("2023")
     With Sheets("FCST")
         .Range("$A$3:$BB" & lr).AutoFilter Field:=3, Criteria1:="2022"
        .UsedRange.Copy Sheets("2022").Range("A1")
        .Range("$A$3:$BB" & lr).AutoFilter Field:=3, Criteria1:="2023"
        .UsedRange.Copy Sheets("2023").Range("A1")
        .Range("$A$3:$BB" & lr).AutoFilter Field:=3, Criteria1:="2024"
        .UsedRange.Copy Sheets("2024").Range("A1")
        .AutoFilter
    End With
    With Sheets(Array("2022", "2023", "2024"))
        With UsedRange
            .Value = .Value
        End With
    End With
    ActiveWorkbook.Save
    Application.ScreenUpdating = True
End Sub
Thank you. Ran into a few snags, but fixed. Takes about the same amount of time to run. I'm even working on 64bit.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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