Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 108
Default Passing Variables Between Procedures

I have a work book with six sheets
Sheet1, Sheet2. Sheet3
Sheet1UL, Sheet2UL. Sheet3UL

The flowing code works as it should for the first sheet in the array passed
to the second procedure €śClearDestination€ť. When it jumps back up to the
first procedure €śArrayLoop€ť, sheetVar(i) holds the next sheet in the array
correctly but when it moves back to €śClearDestination€ť, (sheetVar(i) & "UL")
still holds Sheet1UL. For the life of me I cannot figure out why it dose not
change to Sheet2UL.

ARRRRRR!

Appreciatively,
Arturo


Public NumCopies As Long
Public sheetVar As Variant

Sub ArrayLoop()
sheetVar = Array("Sheet1", "Sheet2", "Sheet3")
For i = LBound(sheetVar) To UBound(sheetVar)
Set sh = Worksheets(sheetVar(i))
Sheets(sheetVar(i)).Select
ClearDestination
Next
End Sub

Sub ClearDestination()
Dim myRange2 As Range

Set myRange2 = Sheets((sheetVar(i) & "UL")).Range("A2:N65000")
myRange2.ClearContents
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 271
Default Passing Variables Between Procedures

"Arturo" wrote:

The flowing code works as it should for the first sheet in the array passed
to the second procedure €śClearDestination€ť. When it jumps back up to the
first procedure €śArrayLoop€ť, sheetVar(i) holds the next sheet in the array
correctly but when it moves back to €śClearDestination€ť, (sheetVar(i) & "UL")
still holds Sheet1UL. For the life of me I cannot figure out why it dose not
change to Sheet2UL.


It's occasions like these that convince you to go into the preferences and
require "Option Explicit" in all your modules. In the Visual Basic Editor,

Tools - Options... - Editor tab - Require Variable Declaration

That will also protect you from typos in variable names.

The problem you're having has to do with what's in the variable i when you
get to the ClearDestination sub.

You might want to re-do the ClearDestination sub so that it requires an
argument or two. That would be better than throwing everything into the
global namespace.

--Shawn
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
Calling Procedures from another excel sheet by passing objects Thomas Auburn Excel Programming 0 May 5th 04 05:33 PM
More questions about variables and procedures... Mike-hime Excel Programming 5 January 8th 04 07:26 AM
Passing Variables Royce[_2_] Excel Programming 1 November 20th 03 02:16 PM
Passing ARGUMENTS between event procedures of a USERFORM jason Excel Programming 8 November 10th 03 07:36 PM


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