Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
set variable once
is it possible to set a variable just once and have many subs use it?
example: user = sheets("1").range("a1") 'i would like to have this set only once at top of module sheet sub temp1() msgbox user 'i would like for this and many other subs to know what 'user' is end sub i know i can define 'user' in a sub, then use sub temp1(user), but i would rather not since there will be so many subs w/ 'user' needed. thanks, mike allen |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
set variable once
Hi
try: dim public user as range set user = sheets("1").range("a1") sub temp1() msgbox user.value end sub -- Regards Frank Kabel Frankfurt, Germany "mike allen" schrieb im Newsbeitrag ... is it possible to set a variable just once and have many subs use it? example: user = sheets("1").range("a1") 'i would like to have this set only once at top of module sheet sub temp1() msgbox user 'i would like for this and many other subs to know what 'user' is end sub i know i can define 'user' in a sub, then use sub temp1(user), but i would rather not since there will be so many subs w/ 'user' needed. thanks, mike allen |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
set variable once
Make it a Public variable, that is declare it at the top of the module,
before any macros, and set it in the first called macro. -- HTH RP (remove nothere from the email address if mailing direct) "mike allen" wrote in message ... is it possible to set a variable just once and have many subs use it? example: user = sheets("1").range("a1") 'i would like to have this set only once at top of module sheet sub temp1() msgbox user 'i would like for this and many other subs to know what 'user' is end sub i know i can define 'user' in a sub, then use sub temp1(user), but i would rather not since there will be so many subs w/ 'user' needed. thanks, mike allen |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
set variable once
"expected: identifier" comes up on "public" in first line. the entire
first line is red, probably pre-warning me of this error. i copied exactly as you have. i must be doing something else wrong. thanks, mike allen "Frank Kabel" wrote in message ... Hi try: dim public user as range set user = sheets("1").range("a1") sub temp1() msgbox user.value end sub -- Regards Frank Kabel Frankfurt, Germany "mike allen" schrieb im Newsbeitrag ... is it possible to set a variable just once and have many subs use it? example: user = sheets("1").range("a1") 'i would like to have this set only once at top of module sheet sub temp1() msgbox user 'i would like for this and many other subs to know what 'user' is end sub i know i can define 'user' in a sub, then use sub temp1(user), but i would rather not since there will be so many subs w/ 'user' needed. thanks, mike allen |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
set variable once
public user as range
sub temp1() set user = sheets("1").range("a1") msgbox user.value end sub You don't use Dim and Public, and you cannot use Set method outside of a procedure. -- HTH RP (remove nothere from the email address if mailing direct) "mike allen" wrote in message ... "expected: identifier" comes up on "public" in first line. the entire first line is red, probably pre-warning me of this error. i copied exactly as you have. i must be doing something else wrong. thanks, mike allen "Frank Kabel" wrote in message ... Hi try: dim public user as range set user = sheets("1").range("a1") sub temp1() msgbox user.value end sub -- Regards Frank Kabel Frankfurt, Germany "mike allen" schrieb im Newsbeitrag ... is it possible to set a variable just once and have many subs use it? example: user = sheets("1").range("a1") 'i would like to have this set only once at top of module sheet sub temp1() msgbox user 'i would like for this and many other subs to know what 'user' is end sub i know i can define 'user' in a sub, then use sub temp1(user), but i would rather not since there will be so many subs w/ 'user' needed. thanks, mike allen |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
set variable once
Hi Bob
thanks for the correction. Should not code directly in OE :-) -- Regards Frank Kabel Frankfurt, Germany "Bob Phillips" schrieb im Newsbeitrag ... public user as range sub temp1() set user = sheets("1").range("a1") msgbox user.value end sub You don't use Dim and Public, and you cannot use Set method outside of a procedure. -- HTH RP (remove nothere from the email address if mailing direct) "mike allen" wrote in message ... "expected: identifier" comes up on "public" in first line. the entire first line is red, probably pre-warning me of this error. i copied exactly as you have. i must be doing something else wrong. thanks, mike allen "Frank Kabel" wrote in message ... Hi try: dim public user as range set user = sheets("1").range("a1") sub temp1() msgbox user.value end sub -- Regards Frank Kabel Frankfurt, Germany "mike allen" schrieb im Newsbeitrag ... is it possible to set a variable just once and have many subs use it? example: user = sheets("1").range("a1") 'i would like to have this set only once at top of module sheet sub temp1() msgbox user 'i would like for this and many other subs to know what 'user' is end sub i know i can define 'user' in a sub, then use sub temp1(user), but i would rather not since there will be so many subs w/ 'user' needed. thanks, mike allen |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
set variable once
I would have said that, but I might have got some flak back :-)
Bob "Frank Kabel" wrote in message ... Hi Bob thanks for the correction. Should not code directly in OE :-) -- Regards Frank Kabel Frankfurt, Germany "Bob Phillips" schrieb im Newsbeitrag ... public user as range sub temp1() set user = sheets("1").range("a1") msgbox user.value end sub You don't use Dim and Public, and you cannot use Set method outside of a procedure. -- HTH RP (remove nothere from the email address if mailing direct) "mike allen" wrote in message ... "expected: identifier" comes up on "public" in first line. the entire first line is red, probably pre-warning me of this error. i copied exactly as you have. i must be doing something else wrong. thanks, mike allen "Frank Kabel" wrote in message ... Hi try: dim public user as range set user = sheets("1").range("a1") sub temp1() msgbox user.value end sub -- Regards Frank Kabel Frankfurt, Germany "mike allen" schrieb im Newsbeitrag ... is it possible to set a variable just once and have many subs use it? example: user = sheets("1").range("a1") 'i would like to have this set only once at top of module sheet sub temp1() msgbox user 'i would like for this and many other subs to know what 'user' is end sub i know i can define 'user' in a sub, then use sub temp1(user), but i would rather not since there will be so many subs w/ 'user' needed. thanks, mike allen |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
set variable once
Hi Bob
but only some minor shooting back <ebg -- Regards Frank Kabel Frankfurt, Germany "Bob Phillips" schrieb im Newsbeitrag ... I would have said that, but I might have got some flak back :-) Bob "Frank Kabel" wrote in message ... Hi Bob thanks for the correction. Should not code directly in OE :-) |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Runtime Error '91' Object variable or With block variable not set | Excel Discussion (Misc queries) | |||
variable height variable width stacked bar charts | Charts and Charting in Excel | |||
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? | Excel Worksheet Functions | |||
setting a range variable equal to the value of a string variable | Excel Programming | |||
Cells.Find error Object variable or With block variable not set | Excel Programming |