Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Just want to run a subroutine in Excel 2013 for first time - Help please! Hi all

ID: 3565800 • Letter: J

Question

Just want to run a subroutine in Excel 2013 for first time - Help please!

Hi all,

I am an amateur coder / data analyst who has been making tiny ad hoc subroutines in Access for decades. Unlike most folks, I mostly make throw-away subroutines. Like, once I've imported yet another uniquely odd dataset, I will never use that code again. I'm not using forms or anything - just running a little pure code, and that's it.

Ok. But now I'm trying Excel VB for the first time.

I tried making my subroutine, one that would show intermediate calculations in the Debug window.

When I hit F5 to run it - just like in Access - a Macro window pops up.

Huh?!?

I haven't made any macros. So it's an empty Macro user interface box.

What the heck... am I supposed to make a macro to run the subroutine?

How do I do that? If I bring up the macro window by itself and try to make a new one, I don't see a way to point it at the subroutine.

But more importantly, why should I have to do this?

I don't have or want any macros, forms, or buttons.

I just want my subroutine to send some results to the VBA debug window.

I have tried googling but I imagine this is an odd "sideways" question. I get 10 million results on macros, VB, Excel, and subroutines, shrug...

Why can't I just hit F5 and run it?? sigh

Can someone please help? I am sure I am ignorant of something known to every Excel VB coder in the world. :-)

Assume I know VB for Access just fine,, but not hardly anything about Excel (macros, forms, or buttons) and you won't go wrong.

I'm using Office 2013 in Win7,, if it matters.

Thanks if you can help!!

Explanation / Answer

A macro in Excel is a procedure (Sub) in a standard module that doesn't have any arguments, e.g.

Sub MyMacro();
    Debug.Print "Hello World"
End Sub

If you want to run such a macro directly from the Visual Basic Editor, you have two options:

1) Click anywhere in the code of the macro, then press F5.

If you press F5 while the insertion point is not within a macro, you'll see the Macro dialog..

2) Press Ctrl+G to activate the Immediate window, type the name of the macro (MyMacro in the above example), then press Enter!