Is It Possible to Call a Macro from a Function?

AlphaMax

New Member
Joined
May 15, 2009
Messages
9
I created a macro (Sub Macro6()) that I want to call like a function on my spreadsheet, is it possible to call a macro from a function? I didn't program the macro manually, I used menu options to record it. But I'd like to be able to use it like a function. The macro does exactly what I need it to do when called as a macro, but when I call Macro6 from a function in a separate cell from my data range, all I get returned is "0".

FYI, my macro does this:

1) Copies 2 rows of existing data
2) Pastes the 2 rows of data as values in cells to the right
3) Sorts the two rows of data, using row 2 as the key


Graphically my macro does this:
Existing data: ................ Macro created data:

1..... 2.... 3.. 4... 5.............. 3.....2....4.. 5... 1
500 200 100 350 350 ......... 100 200 350 350 500

(please ignore the dots, they are spacers only)
;);)
 
Last edited:

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
the answer is Yes AND No...

You CAN call a macro from a UDF function in a cell.

However, that macro CANNOT make any changes to ANY cells ANYWHERE in the book. Cannot change values, copy/paste, delete, change formats....nothing...
 
Upvote 0
You could assign the sub to a button on the tool bar , so all you would have to do is click on it. you might have to modify the macro to use the active cell as the row indicator
 
Upvote 0

Forum statistics

Threads
1,223,264
Messages
6,171,081
Members
452,377
Latest member
bradfordsam

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