General discussion

Locked

A VBA question, how do I?

By jim_rau ·
In Excel using VBA I can write a macro that (conceptually) looks like this:

Sub MyThing()
... let MyVariable = something
... do some stuff with MyVariable
End Sub

What do I do different to pass a variable into MyThing and use it? I have a big chunk of code but I need to use it 10 times with 10 sets of variables. The only way I know how is to copy it 10 times and edit the variables. Then the code is to big to run.

I have to think this is a pretty basic question but it would sure helpme in my understanding. Please be complete!

This conversation is currently closed to new comments.

2 total posts (Page 1 of 1)  
| Thread display: Collapse - | Expand +

All Comments

Collapse -

A VBA question, how do I?

by VinnyD In reply to A VBA question, how do I?

Your code should look something like this

Sub MyThing( MyVariable as String)
... do some stuff with MyVariable
End Sub

To make this work you would have to create a user imput form that lets you enter the variable you want the macro to use.

Then Call this code from the form using the sytax

Call MyThing(Myvariable)

Collapse -

A VBA question, how do I?

by jim_rau In reply to A VBA question, how do I?

Thanks! This exactly the info I needed ...

Back to Windows Forum
2 total posts (Page 1 of 1)  

Related Discussions

Related Forums