How do I separate a Macro into two parts?

arthurz11

Board Regular
Joined
Nov 9, 2007
Messages
80
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

Excel Wisdom
Using a mouse in Excel is the work equivalent of wearing a lanyard when you first get to college
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,214,951
Messages
6,122,442
Members
449,083
Latest member
Ava19

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