LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #12   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 35,218
Default VBA - passing Variables to subroutines

It's not really the "option explicit" that's causing the trouble. It's the
location of the Public declarations.

That line is a directive to VBA that you want it to yell at you if you don't
declare any of the variables you use in that module.

It's a very good idea to have "Option Explicit" at the top of each and every
module--the userform modules, the worksheet modules, the ThisWorkbook module,
and the plain old general modules.



Madduck wrote:

It worked...

its all about the location of my explicit :)

Thanks heaps for the help...

"Dave Peterson" wrote:

How/where did you declare the GemValue variable?

Did you put it in that same general module along with GemRowLoc and GemColLoc?

Option Explicit
Public GemRowLoc As Long
Public GemColLoc As Long
Dim GemValue As Long



Madduck wrote:

Thanks Guys,

I have changed the varible names as suggested...
This script is far from complete, as I'm learning as I go....

as such I have a few "test outputs"

from the form "Gemlist" I can output Gemname to a cell.

What I can't seem to do is pass the value back to the main code...

I did not want to paste the whole code , and clog up the forums, but here is
the entire code behind the form "gemlist"

Sub SubmitButton1_Click()
Sheets("Rift_raid").Select

Gemid

Cells(GemRowloc, GemColloc).Value = Gemname.Value
Range("o1") = ""
Gemname.Value = ""
Gemname.Clear
Gemlist.Hide

End Sub
Sub Gemid()

If Gemname.Value = "Boots" Then
Gemvalue = 1
ElseIf Gemname.Value = "Gloves" Then
Gemvalue = 2
ElseIf Gemname.Value = "Leggings" Then
Gemvalue = 3
ElseIf Gemname.Value = "Chest" Then
Gemvalue = 4
ElseIf Gemname.Value = "Helm" Then
Gemvalue = 5
Else
Gemvalue = 6
End If
Range("o1") = Gemvalue ' for transporting the value out of the subroutine

End Sub

Private Sub userform_Activate()
Gemname.AddItem ("Boots")
Gemname.AddItem ("Gloves")
Gemname.AddItem ("Leggins")
Gemname.AddItem ("Chest")
Gemname.AddItem ("Helm")
Gemname.AddItem ("Shoulders")
Gemname.AddItem ("Weapon")
End Sub


--

Dave Peterson


--

Dave Peterson
 
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
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Passing Variables Jeff Excel Discussion (Misc queries) 1 November 4th 05 06:46 PM
VBA passing variables through a function Jeff Excel Discussion (Misc queries) 2 November 3rd 05 11:23 PM
Passing variables between a form and macro David New Users to Excel 1 October 5th 05 04:42 AM
Passing variables between a form and macro David New Users to Excel 4 September 23rd 05 11:57 AM


All times are GMT +1. The time now is 06:27 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"