Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default userform variable as global

Hi,

I have a userform with a field for first name and a field for last nam
and an OK command button that executes the macro.

I store the last name and first name into variables and i want to b
able to use them in other procedures. for example

sub Ok_Click()

dim first as string
dim last as string

first = First.Text
last = Last.Text

ActiveSheet.Range("A1").Value = first & " " & last
Call upper

End sub

then in a module

sub upper()
ActiveSheet.Range("A2").Value = UCase(last)
end sub

When i call the upper procedure from the ok_click procedure, it doesn'
work. this is probably very dumb, but any help would be appreciated.
thanks

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

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default userform variable as global

You have declared first and last as procedure level variables, so as soon as
the proc ends, they are gone. You also need to reference the form class.
Try

dim first as string
dim last as string

sub Ok_Click()

first = First.Text
last = Last.Text

ActiveSheet.Range("A1").Value = first & " " & last
Call upper

End sub

then in a module

sub upper()
ActiveSheet.Range("A2").Value = UCase(Userform1.last)
end sub



--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"crew3407 " wrote in message
...
Hi,

I have a userform with a field for first name and a field for last name
and an OK command button that executes the macro.

I store the last name and first name into variables and i want to be
able to use them in other procedures. for example

sub Ok_Click()

dim first as string
dim last as string

first = First.Text
last = Last.Text

ActiveSheet.Range("A1").Value = first & " " & last
Call upper

End sub

then in a module

sub upper()
ActiveSheet.Range("A2").Value = UCase(last)
end sub

When i call the upper procedure from the ok_click procedure, it doesn't
work. this is probably very dumb, but any help would be appreciated.
thanks.


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



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default userform variable as global

thank you once agai

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

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default userform variable as global

actually, i'm having another problem.

even when i reference the form class, there is an error message tha
pops up.

Compile Error: Method or data memeber not found.

What am i doing wrong

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

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default userform variable as global

Have you got the correct form name. I used Userform1 as that is the default,
but if you renamed it, you need to use that name.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"crew3407 " wrote in message
...
actually, i'm having another problem.

even when i reference the form class, there is an error message that
pops up.

Compile Error: Method or data memeber not found.

What am i doing wrong?


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





  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default userform variable as global

yes, I changed the userform name to client, so i used client.las

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

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
Global variable dhstein Excel Discussion (Misc queries) 2 October 30th 09 01:03 PM
Global Variable dhstein Excel Discussion (Misc queries) 4 July 26th 09 05:10 PM
why is it saying sheetcnt is "variable not defined" how to do a global variable to share over multiple functions in vba for excel? Daniel Excel Worksheet Functions 1 July 9th 05 03:05 AM
Global value does not retain value when UserForm is hide Alex[_15_] Excel Programming 1 November 4th 03 10:03 AM
Global variable Don[_11_] Excel Programming 1 October 28th 03 04:15 AM


All times are GMT +1. The time now is 04:25 PM.

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"