Macro code is too long and will not run

nachousa

New Member
Joined
Jun 11, 2010
Messages
47
I have a code that is way too long so I keep getting the error: "Procedure too large". Is there a way to fix it? I dont know how to write the code another way.

This is my code. This is just for 1. There are about 37. Maybe there's another way to do it.
the code is just if "K7" = 1 then do ALL that. (goes up to if "K7" = 37 do something, and maybe more)
The code works fine if I only do around 10 but anymore more than that is too much.

Any Ideas?

Code:
Sheets("Sheet3").Select
If Range("K7").Value = 1 Then
Sheets("sheet1").Select
Rows("1:1").Select
ActiveSheet.AutoFilterMode = False
With ActiveSheet.Range("A1").CurrentRegion
        .AutoFilter field:=1, Criteria1:="AW01 AWP Baltimore"
        ActiveSheet.Range("$A$1:$AL$65000").AutoFilter field:=31, Criteria1:=Array("Consig. Transit", "Damage", "Good", "QI", "Sales"), Operator:=xlFilterValues
        .AutoFilter field:=5, Criteria1:="01/2009"
End With
With Range("AM1")
   .Formula = "=subtotal(9,h:h)"
   .Value = .Value
End With
Selection.AutoFilter
Sheets("INV").Range("G6").Value = Sheets("Sheet1").Range("AM1").Value
Sheets("INV").Select
Sheets("sheet1").Select
Rows("1:1").Select
ActiveSheet.AutoFilterMode = False
With ActiveSheet.Range("A1").CurrentRegion
        .AutoFilter field:=1, Criteria1:="AW02 Norfolk"
        ActiveSheet.Range("$A$1:$AL$65000").AutoFilter field:=31, Criteria1:=Array("Consig. Transit", "Damage", "Good", "QI", "Sales"), Operator:=xlFilterValues
        .AutoFilter field:=5, Criteria1:="01/2009"
End With
With Range("AM1")
   .Formula = "=subtotal(9,h:h)"
   .Value = .Value
End With
Selection.AutoFilter
Sheets("INV").Range("G7").Value = Sheets("Sheet1").Range("AM1").Value
Sheets("INV").Select
 
Sheets("sheet1").Select
Rows("1:1").Select
ActiveSheet.AutoFilterMode = False
With ActiveSheet.Range("A1").CurrentRegion
        .AutoFilter field:=1, Criteria1:="AW03 AWP Charleston"
        ActiveSheet.Range("$A$1:$AL$65000").AutoFilter field:=31, Criteria1:=Array("Consig. Transit", "Damage", "Good", "QI", "Sales"), Operator:=xlFilterValues
        .AutoFilter field:=5, Criteria1:="01/2009"
End With
With Range("AM1")
   .Formula = "=subtotal(9,h:h)"
   .Value = .Value
End With
Selection.AutoFilter
Sheets("INV").Range("G8").Value = Sheets("Sheet1").Range("AM1").Value
Sheets("INV").Select
Sheets("Sheet1").Select
Rows("1:1").Select
ActiveSheet.AutoFilterMode = False
With ActiveSheet.Range("A1").CurrentRegion
        .AutoFilter field:=1, Criteria1:="AW04 AWP HOU Gulfstream"
        ActiveSheet.Range("$A$1:$AL$65000").AutoFilter field:=31, Criteria1:=Array("Consig. Transit", "Damage", "Good", "QI", "Sales"), Operator:=xlFilterValues
        .AutoFilter field:=5, Criteria1:="01/2009"
End With
With Range("AM1")
   .Formula = "=subtotal(9,h:h)"
   .Value = .Value
End With
Selection.AutoFilter
Sheets("INV").Range("G9").Value = Sheets("Sheet1").Range("AM1").Value
Sheets("INV").Select
Sheets("Sheet1").Select
Rows("1:1").Select
ActiveSheet.AutoFilterMode = False
With ActiveSheet.Range("A1").CurrentRegion
        .AutoFilter field:=1, Criteria1:="AW05 New Orleans Rail"
        ActiveSheet.Range("$A$1:$AL$65000").AutoFilter field:=31, Criteria1:=Array("Consig. Transit", "Damage", "Good", "QI", "Sales"), Operator:=xlFilterValues
         .AutoFilter field:=5, Criteria1:="01/2009"
End With
With Range("AM1")
   .Formula = "=subtotal(9,h:h)"
   .Value = .Value
End With
Selection.AutoFilter
Sheets("INV").Range("G10").Value = Sheets("Sheet1").Range("AM1").Value
Sheets("INV").Select
Sheets("Sheet1").Select
Rows("1:1").Select
ActiveSheet.AutoFilterMode = False
With ActiveSheet.Range("A1").CurrentRegion
        .AutoFilter field:=1, Criteria1:="AW06 AWP Mobile"
        ActiveSheet.Range("$A$1:$AL$65000").AutoFilter field:=31, Criteria1:=Array("Consig. Transit", "Damage", "Good", "QI", "Sales"), Operator:=xlFilterValues
        .AutoFilter field:=5, Criteria1:="01/2009"
End With
With Range("AM1")
   .Formula = "=subtotal(9,h:h)"
   .Value = .Value
End With
Selection.AutoFilter
Sheets("INV").Range("G11").Value = Sheets("Sheet1").Range("AM1").Value
Sheets("INV").Select
Sheets("Sheet1").Select
Rows("1:1").Select
ActiveSheet.AutoFilterMode = False
With ActiveSheet.Range("A1").CurrentRegion
        .AutoFilter field:=1, Criteria1:="AW07 AWP San Francisco"
        ActiveSheet.Range("$A$1:$AL$65000").AutoFilter field:=31, Criteria1:=Array("Consig. Transit", "Damage", "Good", "QI", "Sales"), Operator:=xlFilterValues
        .AutoFilter field:=5, Criteria1:="01/2009"
End With
With Range("AM1")
   .Formula = "=subtotal(9,h:h)"
   .Value = .Value
End With
Selection.AutoFilter
Sheets("INV").Range("G12").Value = Sheets("Sheet1").Range("AM1").Value
Sheets("INV").Select
Sheets("Sheet1").Select
Rows("1:1").Select
ActiveSheet.AutoFilterMode = False
With ActiveSheet.Range("A1").CurrentRegion
        .AutoFilter field:=1, Criteria1:="AW08 AWP Portland"
        ActiveSheet.Range("$A$1:$AL$65000").AutoFilter field:=31, Criteria1:=Array("Consig. Transit", "Damage", "Good", "QI", "Sales"), Operator:=xlFilterValues
        .AutoFilter field:=5, Criteria1:="01/2009"
End With
With Range("AM1")
   .Formula = "=subtotal(9,h:h)"
   .Value = .Value
End With
Selection.AutoFilter
Sheets("INV").Range("G13").Value = Sheets("Sheet1").Range("AM1").Value
Sheets("INV").Select
 
Last edited:

Excel Facts

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.

nachousa

New Member
Joined
Jun 11, 2010
Messages
47
you can ignore the code. I just want to know if there's a way to run the code when is this long.
 

Watch MrExcel Video

Forum statistics

Threads
1,133,720
Messages
5,660,511
Members
418,581
Latest member
gtarr

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