Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Passing variables in macros

I thought I had this figured out; but apparently not.

I have variables I'm passing between subs and they are not being returned.

here's the code:
===========================================

Public Next_Prog, Last_Prog, Start_add As Variant
Public ProgName, Levels As String
-----------------------------------------------------------------------
Range("A2").Select
Prog_row = ActiveCell.Row
Selection.End(xlDown).Select
Last_Prog = ActiveCell.Row
Range("A2").Select
ProgName = ActiveCell.Value
Levels = ActiveCell.Offset(0, 1)
ActiveCell.Offset(1, 0).Select
Next_Prog = ActiveCell.Address

Range("D4").Select
Row_nbr = ActiveCell.Row
Start_add = ActiveCell.Address
Selection.End(xlDown).Select
Last_row = ActiveCell.Row
Range(Start_add).Select
Do While ActiveCell.Row <= Last_row
If ActiveCell.Value = ProgName Then
.... do statements

End If
Call Set_Prg_Name
Loop
---------------------------------------------
Sub Set_Prg_Name()
Range(Next_Prog).Select
If ActiveCell.Row Last_Prog Then

Else
ProgName = ActiveCell.Value
Levels = ActiveCell.Offset(0, 1)
ActiveCell.Offset(1, 0).Select
Next_Prog = ActiveCell.Address
Range(Start_add).Select
End If <the var value changes
here but is not
<transfered back
when returning to the
<previous calling sub.
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 449
Default Passing variables in macros

Hi

See if this makes sense to you:

Sub Test()
Dim A As Long, B As Long
A = 10
MsgBox "A is " & A
Call ByRefMacro(A)
MsgBox "A is " & A

B = 10
MsgBox "B is " & B
Call ByValMacro(B)
MsgBox "B is " & B
End Sub

Sub ByRefMacro(ByRef X As Long)
X = X * 2
MsgBox "ByRefMacro says " & X
End Sub

Sub ByValMacro(ByVal X As Long)
X = X * 2
MsgBox "ByValMacro says " & X
End Sub


HTH. Best wishes Harald


"El Bee" wrote in message
...
I thought I had this figured out; but apparently not.

I have variables I'm passing between subs and they are not being returned.

here's the code:
===========================================

Public Next_Prog, Last_Prog, Start_add As Variant
Public ProgName, Levels As String
-----------------------------------------------------------------------
Range("A2").Select
Prog_row = ActiveCell.Row
Selection.End(xlDown).Select
Last_Prog = ActiveCell.Row
Range("A2").Select
ProgName = ActiveCell.Value
Levels = ActiveCell.Offset(0, 1)
ActiveCell.Offset(1, 0).Select
Next_Prog = ActiveCell.Address

Range("D4").Select
Row_nbr = ActiveCell.Row
Start_add = ActiveCell.Address
Selection.End(xlDown).Select
Last_row = ActiveCell.Row
Range(Start_add).Select
Do While ActiveCell.Row <= Last_row
If ActiveCell.Value = ProgName Then
.... do statements

End If
Call Set_Prg_Name
Loop
---------------------------------------------
Sub Set_Prg_Name()
Range(Next_Prog).Select
If ActiveCell.Row Last_Prog Then

Else
ProgName = ActiveCell.Value
Levels = ActiveCell.Offset(0, 1)
ActiveCell.Offset(1, 0).Select
Next_Prog = ActiveCell.Address
Range(Start_add).Select
End If <the var value
changes
here but is not
<transfered back
when returning to the
<previous calling
sub.
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Passing variables in macros

I'm confused. When I posted this question it said there was an error. I
thought this ment the message would not be posted. It's now going to appear
3 times.

Sorry for all this.

"El Bee" wrote:

I thought I had this figured out; but apparently not.

I have variables I'm passing between subs and they are not being returned.

here's the code:
===========================================

Public Next_Prog, Last_Prog, Start_add As Variant
Public ProgName, Levels As String
-----------------------------------------------------------------------
Range("A2").Select
Prog_row = ActiveCell.Row
Selection.End(xlDown).Select
Last_Prog = ActiveCell.Row
Range("A2").Select
ProgName = ActiveCell.Value
Levels = ActiveCell.Offset(0, 1)
ActiveCell.Offset(1, 0).Select
Next_Prog = ActiveCell.Address

Range("D4").Select
Row_nbr = ActiveCell.Row
Start_add = ActiveCell.Address
Selection.End(xlDown).Select
Last_row = ActiveCell.Row
Range(Start_add).Select
Do While ActiveCell.Row <= Last_row
If ActiveCell.Value = ProgName Then
.... do statements

End If
Call Set_Prg_Name
Loop
---------------------------------------------
Sub Set_Prg_Name()
Range(Next_Prog).Select
If ActiveCell.Row Last_Prog Then

Else
ProgName = ActiveCell.Value
Levels = ActiveCell.Offset(0, 1)
ActiveCell.Offset(1, 0).Select
Next_Prog = ActiveCell.Address
Range(Start_add).Select
End If <the var value changes
here but is not
<transfered back
when returning to the
<previous calling sub.
End Sub

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
Passing Variables Jeff Excel Discussion (Misc queries) 1 November 4th 05 06:46 PM
Passing variables from one sub to another Yasha Avshalumov Excel Programming 4 August 19th 05 04:52 PM
Passing Variables Paula[_3_] Excel Programming 1 August 23rd 04 06:55 PM
passing variables Squid[_2_] Excel Programming 1 July 27th 04 03:47 AM
Passing Variables Tom Ogilvy Excel Programming 0 July 23rd 04 04:19 PM


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