Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Passing the value of listbox to other Subs


I'm having a major headache trying to define a variable through
listbox and then having that variable passed through to othe
modules/subs.

Basically, I want a listbox which obtains an input from the user an
stores it in a variable. Then I want a second userform which obtains
second variable. Then I want to be able to call a specific sub based o
those two parameters.

My problem is that when I reference the variable from another sub th
value shows as "". I've tried to define a Public variable but tha
only seems to work within one module at a time.

Below is the code that I'm trying to use. Any help is greatl
appreciated. Thx!!


Sub WorkBook_Open()

Call ChooseLocation
ActiveWorkbook.Save
ActiveWorkbook.Close
End Sub

Sub ChooseLocation()
LocationForm.ListBox1.AddItem "Location1"
LocationForm.ListBox1.AddItem "Location2"
LocationForm.ListBox1.AddItem "Location3"

LocationForm.Show

End Sub

Sub CommandButton1_Click()
If Location = "Location3" Then
Call Location3Routine
' Above routine needs to be created later
Else
Call ChooseOption
End If

Unload LocationForm

End Sub

Sub ListBox1_Click()
Location = ListBox1.Value ** This is the variable that I need t
reference in later areas of the program **
End Sub

Sub ChooseOption()
OptionForm.Show
End Sub


Sub OptionButton1_Click()
End Sub

Sub OptionButton2_Click()
End Sub

Sub OptionButton3_Click()
End Sub

Sub OptionButton4_Click()
End Sub

Sub SelectionButton_Click()
If Location = "Location1" Then
** Here's where I want to define additional variables based on th
value of LOCATION except I cannot find a way to carry that valu
through to this point of the program **

' Define variables based on Location
End If

If OptionButton1 Then
' Code for Option1
End If

Unload OptionForm

End Su

--
Cygnus24
-----------------------------------------------------------------------
Cygnus241's Profile: http://www.excelforum.com/member.php...fo&userid=2722
View this thread: http://www.excelforum.com/showthread.php?threadid=46738

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 61
Default Passing the value of listbox to other Subs

Two options you might want to consider

1. Export/Import
The easist way I dealt with this sort of stuff is to save the choice to a
spreadsheet once its selected.
I generally have a worksheet that contains all the choices and the option a
user selects.
This way I always have a hard copy of the choices a user selects for later
reference.

Then simply import the data back in to use.

2. Make a function to pass variables

Alternatively you could just make the other sub a function and run it that
way

Sub Dummy
Dim Option as String
Dim result as string
Dim i as intiger

Option = listbox1.value
i = 10
result = Values(Option, i)

End Sub

Function Values(Option As String, i As Integer)
....
Values = ...
End Function

Hope this helps



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
General Question regarding passing cells, ranges, cell values through subs & functions [email protected] Excel Programming 1 September 5th 04 06:46 PM
General Question regarding passing cells, ranges, cell values through subs & functions [email protected] Excel Programming 2 September 5th 04 06:03 AM
General Question regarding passing cells, ranges, cell values through subs & functions [email protected] Excel Programming 1 September 4th 04 10:40 PM
General Question regarding passing cells, ranges, cell values through subs & functions [email protected] Excel Programming 1 September 4th 04 09:09 PM
Passing values between 2 subs ? [email protected] Excel Programming 1 November 21st 03 05:56 PM


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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"