ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   passing value with button to macros (https://www.excelbanter.com/excel-programming/286907-passing-value-button-macros.html)

pabs[_13_]

passing value with button to macros
 
is it possible to pass a particular value with a button to a macro?

in my case I have 12 buttons (one for each month).
If the user hits a particular button I want to pass along the month
corresponding to that button to my main macro.
The main macro is always the same. it already has logic in it to
handle each month.

I could have a small macro for each button that would then call my main
macor with the corresponding month but that doesn't seem very clean or
practical.

there must be an easy way to always call the macro with a different
string as a paramater..

I'm open to any ideas here...

is there a way to get a string from a select list? in other words I
could have a list with all my months and the user would select the
desired month from the list and then hit the run button (only one
button as oppose to 12)! ..

that would be nicer but I am unsure how to that


thanks for any help

Pabs


---
Message posted from http://www.ExcelForum.com/


Don Guillett[_4_]

passing value with button to macros
 
Instead of 12 buttons, why not just a drop down list (data validation) for
the months. Then the macro can refer to the cell.

mymonth=range("b4")
then
myval=choose(mymonth,1,2,3,4,5,6,7,8,9,10,11,12)

--
Don Guillett
SalesAid Software

"pabs " wrote in message
...
is it possible to pass a particular value with a button to a macro?

in my case I have 12 buttons (one for each month).
If the user hits a particular button I want to pass along the month
corresponding to that button to my main macro.
The main macro is always the same. it already has logic in it to
handle each month.

I could have a small macro for each button that would then call my main
macor with the corresponding month but that doesn't seem very clean or
practical.

there must be an easy way to always call the macro with a different
string as a paramater..

I'm open to any ideas here...

is there a way to get a string from a select list? in other words I
could have a list with all my months and the user would select the
desired month from the list and then hit the run button (only one
button as oppose to 12)! ..

that would be nicer but I am unsure how to that


thanks for any help

Pabs


---
Message posted from
http://www.ExcelForum.com/




Paul

passing value with button to macros
 
You could use a ComboBox attached to a list in a worksheet
representing the months. if you want to include the year,
the year could be centralised and the months can include
the year by using a formula. eg. 2004 in cell A1. The list
running down could include eg. "Jan-"&$A$1. The month is
selected in the combobox. That value can be passed to the
main macro by picking it up as a variable.

eg.
Dim vMonth as variant

vMonth = Userform1.ComboBox.Value

vMonth can be used by your coding.

-----Original Message-----
is it possible to pass a particular value with a button

to a macro?

in my case I have 12 buttons (one for each month).
If the user hits a particular button I want to pass along

the month
corresponding to that button to my main macro.
The main macro is always the same. it already has logic

in it to
handle each month.

I could have a small macro for each button that would

then call my main
macor with the corresponding month but that doesn't seem

very clean or
practical.

there must be an easy way to always call the macro with a

different
string as a paramater..

I'm open to any ideas here...

is there a way to get a string from a select list? in

other words I
could have a list with all my months and the user would

select the
desired month from the list and then hit the run button

(only one
button as oppose to 12)! ..

that would be nicer but I am unsure how to that


thanks for any help

Pabs


---
Message posted from http://www.ExcelForum.com/

.


pabs[_14_]

passing value with button to macros
 
much better!

it works real well...it's actually the way I wanted to do it in the
first place..just didn't know how to go about it..
thanks!


I now have a form where the user can select from a list of months and
then a button to generate some results based on this..

basically I'm generating worksheets for many people (let's say 20) for
the given month.

How hard would it be to be able to exclude certain people?
in other words I could have a menu where I sould select as many people
as I want. for example if I want to generate the workbooks for 3
people (not all 20) for any given month. I would click on their names
and the month I want and run my macros...

on the macro side I already have the code that handles each person
individualy.. I would just need to be able to pass the name of the
chosen persons (from the list in my form)

what would be the correct syntax for this?

thanks

PAbs


---
Message posted from http://www.ExcelForum.com/



All times are GMT +1. The time now is 11:09 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com