Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Returning vars to calling sub

I'm not sure what I'm doing wrong here. the first sub calls the second sub
which sets 2 vars (prog_name & Levels). These values are not being returned
to the calling sub.

thanks for looking.

see below.


Public Next_Prog, Last_Prog, Start_add As Variant
Public ProgName, Levels As String



Sub Step2_Extract_Profiles()
Dim logOn, Prof_row, Row_nbr, Last_row As Variant
Dim copy_From, ProgName, Levels As String

Dim rCell As Range
Dim cell As Range

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
End If
GoSub Set_Prg_Name
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub



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 'values change here but are not
returned to calling sub
end if
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Returning vars to calling sub

You are using a GoSub command to call another procedure, which is incorrect.
GoSub is used to call a subroutine within the same procedure. Try the Call
command instead. Also, delete the End If statement just before the GoSub.

Hope this helps,

Hutch

"El Bee" wrote:

I'm not sure what I'm doing wrong here. the first sub calls the second sub
which sets 2 vars (prog_name & Levels). These values are not being returned
to the calling sub.

thanks for looking.

see below.


Public Next_Prog, Last_Prog, Start_add As Variant
Public ProgName, Levels As String



Sub Step2_Extract_Profiles()
Dim logOn, Prof_row, Row_nbr, Last_row As Variant
Dim copy_From, ProgName, Levels As String

Dim rCell As Range
Dim cell As Range

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
End If
GoSub Set_Prg_Name
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub



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 'values change here but are not
returned to calling sub
end if
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Returning vars to calling sub

Tom,

I caught the Gosub mistake and changed it to a call. The "end if" was part
of a previous "if" statement; sorry for the confusion. I copied a portion of
the macro and didn't edit it close enough.

With those corrections made. I added a msgbox in the calling sub routine to
see if the values would be change, and they were, but they are not being
returned to the calling sub routine. The original values for ProgName and
Levels do not get updated by the call to the Set_Prg_Name sub.

"Tom Hutchins" wrote:

You are using a GoSub command to call another procedure, which is incorrect.
GoSub is used to call a subroutine within the same procedure. Try the Call
command instead. Also, delete the End If statement just before the GoSub.

Hope this helps,

Hutch

"El Bee" wrote:

I'm not sure what I'm doing wrong here. the first sub calls the second sub
which sets 2 vars (prog_name & Levels). These values are not being returned
to the calling sub.

thanks for looking.

see below.


Public Next_Prog, Last_Prog, Start_add As Variant
Public ProgName, Levels As String



Sub Step2_Extract_Profiles()
Dim logOn, Prof_row, Row_nbr, Last_row As Variant
Dim copy_From, ProgName, Levels As String

Dim rCell As Range
Dim cell As Range

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
End If
GoSub Set_Prg_Name
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub



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 'values change here but are not
returned to calling sub
end if
End Sub

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,069
Default Returning vars to calling sub

You have ProgName and Levels declared as Public variables, and they are
declared again as private variables within the Step2_Extract_Profiles
procedure. The locally declared variable will take preference within a
procedure over a Public variable with the same name. Your called procedure is
updating the Public variables, but Step2_Extract_Profiles is working with the
ProgName and Levels variables declared within itself. Remove ProgName and
Levels from the DIm statement in Step2_Extract_Profiles.

Hutch

"El Bee" wrote:

Tom,

I caught the Gosub mistake and changed it to a call. The "end if" was part
of a previous "if" statement; sorry for the confusion. I copied a portion of
the macro and didn't edit it close enough.

With those corrections made. I added a msgbox in the calling sub routine to
see if the values would be change, and they were, but they are not being
returned to the calling sub routine. The original values for ProgName and
Levels do not get updated by the call to the Set_Prg_Name sub.

"Tom Hutchins" wrote:

You are using a GoSub command to call another procedure, which is incorrect.
GoSub is used to call a subroutine within the same procedure. Try the Call
command instead. Also, delete the End If statement just before the GoSub.

Hope this helps,

Hutch

"El Bee" wrote:

I'm not sure what I'm doing wrong here. the first sub calls the second sub
which sets 2 vars (prog_name & Levels). These values are not being returned
to the calling sub.

thanks for looking.

see below.


Public Next_Prog, Last_Prog, Start_add As Variant
Public ProgName, Levels As String



Sub Step2_Extract_Profiles()
Dim logOn, Prof_row, Row_nbr, Last_row As Variant
Dim copy_From, ProgName, Levels As String

Dim rCell As Range
Dim cell As Range

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
End If
GoSub Set_Prg_Name
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub



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 'values change here but are not
returned to calling sub
end if
End Sub

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 58
Default Returning vars to calling sub

Thanks, Tom!!

That was another oversight on my part. It's now working!!!

"Tom Hutchins" wrote:

You have ProgName and Levels declared as Public variables, and they are
declared again as private variables within the Step2_Extract_Profiles
procedure. The locally declared variable will take preference within a
procedure over a Public variable with the same name. Your called procedure is
updating the Public variables, but Step2_Extract_Profiles is working with the
ProgName and Levels variables declared within itself. Remove ProgName and
Levels from the DIm statement in Step2_Extract_Profiles.

Hutch

"El Bee" wrote:

Tom,

I caught the Gosub mistake and changed it to a call. The "end if" was part
of a previous "if" statement; sorry for the confusion. I copied a portion of
the macro and didn't edit it close enough.

With those corrections made. I added a msgbox in the calling sub routine to
see if the values would be change, and they were, but they are not being
returned to the calling sub routine. The original values for ProgName and
Levels do not get updated by the call to the Set_Prg_Name sub.

"Tom Hutchins" wrote:

You are using a GoSub command to call another procedure, which is incorrect.
GoSub is used to call a subroutine within the same procedure. Try the Call
command instead. Also, delete the End If statement just before the GoSub.

Hope this helps,

Hutch

"El Bee" wrote:

I'm not sure what I'm doing wrong here. the first sub calls the second sub
which sets 2 vars (prog_name & Levels). These values are not being returned
to the calling sub.

thanks for looking.

see below.


Public Next_Prog, Last_Prog, Start_add As Variant
Public ProgName, Levels As String



Sub Step2_Extract_Profiles()
Dim logOn, Prof_row, Row_nbr, Last_row As Variant
Dim copy_From, ProgName, Levels As String

Dim rCell As Range
Dim cell As Range

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
End If
GoSub Set_Prg_Name
Else
ActiveCell.Offset(1, 0).Select
End If
Loop
End Sub



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 'values change here but are not
returned to calling sub
end if
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
Returning values to calling sub El Bee Excel Programming 0 February 12th 09 05:11 PM
Pivot tables - can change row/col vars but can't get rid of existing vars Andreww Excel Programming 0 May 25th 07 11:50 AM
Calling a function and then returning CLamar Excel Discussion (Misc queries) 4 June 19th 06 06:47 PM
functions & range vars [email protected] Excel Programming 2 July 15th 05 07:26 PM
Global vars Nath Excel Programming 1 July 13th 04 04:20 PM


All times are GMT +1. The time now is 02:35 AM.

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"