Same Variable But In Different Sub's

M

M Chahal

Hi,

Please see code below.....
Sub X1()
V1 = "GI-ACE"
Sheets(V1).Select
Call S
End Sub

Sub S()
ActiveSheet.UnProtect ("util")
Range("B43:BW200").Select
Selection.ClearContents
Sheets("Data").Select
Selection.AutoFilter Field:=1, Criteria1:=V1 '!!!!THIS IS WHERE IT
FAILS!!!!'
Selection.AutoFilter Field:=145, Criteria1:="CHECK"
Range("E3:G800").Select
Selection.Copy
Sheets(V1).Select '!!!!THIS IS WHERE IT FAILS!!!!'
Range(B42).Select
Selection.PasteSpecial Paste:=xlPasteValues
End Sub

Basically, I need to use a defined variable (V1) in other subs, how can I do
that without stating it in each sub??

Any help appreciated.

MSC
 
S

Stefan Hoffmann

hi,

Basically, I need to use a defined variable (V1) in other subs, how can I do
that without stating it in each sub??
You already got some answers. Have you read them?


mfG
--> stefan <--
 
D

De Jager

M Chahal said:
Hi,

Please see code below.....
Sub X1()
V1 = "GI-ACE"
Sheets(V1).Select
Call S
End Sub

Sub S()
ActiveSheet.UnProtect ("util")
Range("B43:BW200").Select
Selection.ClearContents
Sheets("Data").Select
Selection.AutoFilter Field:=1, Criteria1:=V1 '!!!!THIS IS WHERE IT
FAILS!!!!'
Selection.AutoFilter Field:=145, Criteria1:="CHECK"
Range("E3:G800").Select
Selection.Copy
Sheets(V1).Select '!!!!THIS IS WHERE IT FAILS!!!!'
Range(B42).Select
Selection.PasteSpecial Paste:=xlPasteValues
End Sub

Basically, I need to use a defined variable (V1) in other subs, how can I
do
that without stating it in each sub??

Any help appreciated.

MSC
 
R

R. Heine

M Chahal said:
Hi,

Please see code below.....
Sub X1()
V1 = "GI-ACE"
Sheets(V1).Select
Call S
End Sub

Sub S()
ActiveSheet.UnProtect ("util")
Range("B43:BW200").Select
Selection.ClearContents
Sheets("Data").Select
Selection.AutoFilter Field:=1, Criteria1:=V1 '!!!!THIS IS WHERE IT
FAILS!!!!'
Selection.AutoFilter Field:=145, Criteria1:="CHECK"
Range("E3:G800").Select
Selection.Copy
Sheets(V1).Select '!!!!THIS IS WHERE IT FAILS!!!!'
Range(B42).Select
Selection.PasteSpecial Paste:=xlPasteValues
End Sub

Basically, I need to use a defined variable (V1) in other subs, how can I
do
that without stating it in each sub??

Any help appreciated.

MSC
 
R

RonaldoOneNil

This is Excel code posted in the Access forum, but you can either declare the
variable at the top of the module outside all subs and functions or in your
example below, pass it to the other sub

Sub X1()
V1 = "GI-ACE"
Sheets(V1).Select
Call S(V1)
End Sub

Sub S(V1 as String)
ActiveSheet.UnProtect ("util")
....
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top