Add record macro in existing code

K Jenkins

New Member
Joined
Oct 10, 2018
Messages
7
Hi,

Is there a way to add in an existing VBA code a new macro but from record macro function?+

And if so, how?

Thanks in advance:)
 

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.
Are you asking whether or not you can designate a macro you are recording to be placed in a specific module instead of a new one?
If so, why is that necessary?
If that is not what you are after, please explain in more detail, as your question is not clear.
 
Upvote 0
Hi,

Yes, that is what I am asking:-)

The reason being that there is already a good code written and I just want to add one small procedure to make more automated.

Yes, I understand that it may sound as an exaggeration that I want to press one button instead of two to run the macros:-)

Thanks again.
 
Upvote 0
Yes, I understand that it may sound as an exaggeration that I want to press one button instead of two to run the macros
It sounds like you want to go further than putting it in the same module; it sounds like you want it in the same sub procedure.

The answer is no, you cannot record a macro and have it automatically go into an already existing procedure ("macro"). But it is really easy to combine them into one in the VB Editor.

Let's say that you record two macros, so they look like this in the VB Editor:

Code:
Sub Macro1()

'   Your recorded code here for macro1

End Sub


Sub Macro2()

'   Your recorded code here for macro2

End Sub
Just copy and paste the body of the second macro into the bottom of the first (then delete the second), so it looks like this:
Code:
Sub Macro1()

'   Your recorded code here for macro1

'   Your recorded code here for macro2

End Sub
That's all you have to do.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,248
Members
452,623
Latest member
cliftonhandyman

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