LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 46
Default Global definitions

Hi,

I am using a userform that usings the same defined variables, i.e.
worksheets for several different command buttons.

How do I set up these definitions as 'global' (if thats the right term) so
that I don't have to repeat the definitions for each command_button_click sub?

Example Code:-
Sub UserForm1_Load()

Dim CostWk As Worksheet
Set CostWk = Worksheets("JCOST-ALL")

Dim Costs As String
Costs = "JCOST-ALL"

Dim Rev As String
Rev = "JREV-ALL"


End Sub

Sub CommandButton1_Click()

Dim WBName As String
WBName = ActiveWorkbook.Name

Dim CostWk As Worksheet
Set CostWk = Worksheets("JCOST-ALL")

Dim Costs As String
Costs = "JCOST-ALL"


Application.Sheets(Costs).Visible = True


CostWk.Range("A2:J2").End(xlDown).ClearContents
Windows("Worksheet in Basis (1)").Activate
Range("A2:J2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows(WBName).Activate
CostWk.Select
Range("A2").Select
ActiveSheet.Paste

ActiveWindow.WindowState = xlMaximized

Sheets("Front").Select

Application.Sheets(Costs).Visible = False

End Sub

Sub CommandButton2_Click()

Dim WBName As String
WBName = ActiveWorkbook.Name

Dim RevWk As Worksheet
Set RevWk = Worksheets("JREV-ALL")

Dim Rev As String
Rev = "JREV-ALL"


Application.Sheets(Rev).Visible = True


RevWk.Range("A2:J2").End(xlDown).ClearContents
Windows("Worksheet in Basis (1)").Activate
Range("A2:J2").Select
Range(Selection, Selection.End(xlDown)).Select
Selection.Copy
Windows(WBName).Activate
RevWk.Select
Range("A2").Select
ActiveSheet.Paste

ActiveWindow.WindowState = xlMaximized

Sheets("Front").Select

Application.Sheets(Rev).Visible = False

End Sub

Sub CommandButton3_Click()

Application.Sheets(Costs).Visible = True

End Sub

Sub CommandButton4_Click()

Application.Sheets(Rev).Visible = True

End Sub



Also, any tips on the above would be appreciated.


TIA
Matt
 
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
xl* object definitions ?? Bill Case Excel Programming 3 August 31st 06 09:36 PM
Trouble with 2 range definitions ... Celt[_39_] Excel Programming 7 April 5th 06 04:45 PM
Definitions Nick Excel Discussion (Misc queries) 1 July 1st 05 09:25 AM
Function Definitions Andrew Edmunds Excel Programming 1 January 8th 04 10:56 AM
Operator definitions Niklas[_2_] Excel Programming 2 July 25th 03 01:09 PM


All times are GMT +1. The time now is 06:50 PM.

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

About Us

"It's about Microsoft Excel"