Referencing other macros/modules

mlopes1

Board Regular
Joined
Jul 14, 2002
Messages
114
I have a macro written that hides all empty rows on a certain workbook. I have another macro written that prints certain worksheets. I would like for the Print macro to call the EmptyRow macro, so that its code is run first.

In other words, I don't want the Print macro to run without making sure the Empty row has performed first. However, the EmptyRow can be performed without printing.

Right now I just copied and pasted all of the Empty macro's code into the Print macro so that it has to be run, but then realized there must be a more efficient way. Can I somehow call or reference the other macro? Thanks in advance,

Mark
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
There surely is a more efficient way. There's a couple of ways to do it. Assuming that both macros are in the same workbook.

Maybe the best way to accomplish this is to create a third macro that calls each of your macros in sequence. You can just call this macro "Main" or "ClearAndPrint" or something sensebile like that, e.g.:

<pre>
Public Sub ClearAndPrint()
EmptyRow
'Insert your print macro name here
End Sub</pre>

Pretty straightfoward. An alternative way to do this would be to make the first line of your print macro call the "EmptyRow" macro. However, if you follow my previous advice, this allows your Print macro to stay reasonable generic and easier to reuse.

HTH
 
Upvote 0

Forum statistics

Threads
1,214,832
Messages
6,121,849
Members
449,051
Latest member
excelquestion515

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