How can I pass variables betweet two Subs in Excel VBA? -


i know how pass variables between 2 subs when calling sub running action within sub containing variables set up, want call variable setup sub within routine macro can not correct place declare variables work. want have variable set separate called other subs. code below not work 2 subs

sub x_variables(s1, s2, s3, rng1, rng2, rng3) '  ' x - defined cell names  - anflighttext , auflighttext , abflighttext  dim s1   worksheet dim s2   worksheet dim s3   worksheet dim rng1  range dim rng2  range dim rng3  range  set s1 = sheets("5_angebot")        ' worksheet set s2 = sheets("5_auftragsb")      ' worksheet set s3 = sheets("5_abschluss")      ' worksheet set rng1 = s1.range("b15")          ' end on cell set rng2 = s2.range("b15")          ' end on cell set rng3 = s3.range("b15")          ' end on cell  end sub 

called by

sub x_offer_hide_flight_text() ' ' ***** hide flight text  *****  ' x - defined cell names  - anflighttext , auflighttext , abflighttext ' x (s1, s2, s3, rng1, rng2, rng3)   '  ***** set veriables *****  call x_variables  ' *****  ' hide rows application.screenupdating = false  ' not see screen updating  s1.select range("anflighttext").select        ' x selection.entirerow.hidden = true rng1.select  s2.select range("auflighttext").select        ' x selection.entirerow.hidden = true rng2.select  s3.select range("abflighttext").select        ' x selection.entirerow.hidden = true rng3.select  s1.select  application.screenupdating = true  ' see screen updating  end sub 

you have declare variables global, outside of sub.

public s1   worksheet public s2   worksheet public s3   worksheet public rng1  range public rng2  range public rng3  range  sub x_variables() '  ' x - defined cell names  - anflighttext , auflighttext , abflighttext  set s1 = sheets("5_angebot")        ' worksheet set s2 = sheets("5_auftragsb")      ' worksheet set s3 = sheets("5_abschluss")      ' worksheet set rng1 = s1.range("b15")          ' end on cell set rng2 = s2.range("b15")          ' end on cell set rng3 = s3.range("b15")          ' end on cell  end sub 

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -