How do I separate a Macro into two parts?

arthurz11

Board Regular
Joined
Nov 9, 2007
Messages
81
Office Version
  1. 2021
Platform
  1. Windows
I created a macro (Ctrl-N). When I executed the macro, I got a message error Procedure Too Long. How can I separate it or split it into two parts so that it will work? In other words, I can cut out half of the code and then paste it somewhere else (not sure where), but it will still work using the Ctrl-N.
 

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.
Create another subroutine called Part2 for example. Cut the lower portion of code from the original subroutine and paste it into the new subroutine that you created. At the bottom of the original subroutine add the following line of code Call Part2

So you will end up with something like the following:
VBA Code:
Sub Original()
' First half of code
    Call Part2
End Sub

Sub Part2()
' Last half of code
End Sub

This may create issues with variable names that you will have to handle. ;)

You may want to see if you can just shorten your current code
 
Last edited:
Upvote 0
Solution
Create another subroutine called Part2 for example. Cut the lower portion of code from the original subroutine and paste it into the new subroutine that you created. At the bottom of the original subroutine add the following line of code Call Part2

So you will end up with something like the following:
VBA Code:
Sub Original()
' First half of code
    Call Part2
End Sub

Sub Part2()
' Last half of code
End Sub

This may create issues with variable names that you will have to handle. ;)

You may want to see if you can just shorten your current code
I will give it a try.
 
Upvote 0

Forum statistics

Threads
1,215,453
Messages
6,124,925
Members
449,195
Latest member
Stevenciu

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