Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Passing Variables within For loops to other modules


Hi.

I has a hugh piece of code which was too big to compile, so I have hav
had to split it off into separate modules. I keep on getting subscrip
out of range errors now.


Public I
Public p

Sub CreateMardakInput()

Application.ScreenUpdating = True

Sheets("AutoInput").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.Delete

Sheets.Add.Name = "AutoInput"

Sheets("AutoInput").Move Befo=Sheets(1)
Sheets("AutoInput").Select

' Dim p As Integer
p = 2

For I = 1 To Sheets.Count
Sheets(I).Select
GoSub DoCopy
Next I

Exit Sub

DoCopy:

If Cells(1, 1) = "Sub-Contract Payment" Then ' If A1 = LO Templat
then:
' Test for name in box
link through if so
' for per subcontractor.
'Module3.PartOne (p)
'Module4.PartTwo (p)
'Module5.PartThree (p)
'Module6.PartFour (p)
'Module7.PartFive (p)

Call PartOne
Call PartTwo
Call PartThree
Call PartFour
Call PartFive

End If

Return

End Sub

For some reason the I variable is not picked up by the other modules.
have declared I & p as public in these modules. I am stuck.

Please help!

Thanks,
To

--
tomjerm
-----------------------------------------------------------------------
tomjermy's Profile: http://www.excelforum.com/member.php...fo&userid=2466
View this thread: http://www.excelforum.com/showthread.php?threadid=57419

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Passing Variables within For loops to other modules

If you declared I in this main module and also declared I in each of the other
modules, then VBA will use the one closest to the code--within that same module.

Try removing the declarations from the other modules (Just declare it public one
time).

tomjermy wrote:

Hi.

I has a hugh piece of code which was too big to compile, so I have have
had to split it off into separate modules. I keep on getting subscript
out of range errors now.

Public I
Public p

Sub CreateMardakInput()

Application.ScreenUpdating = True

Sheets("AutoInput").Select
Application.CutCopyMode = False
ActiveWindow.SelectedSheets.Delete

Sheets.Add.Name = "AutoInput"

Sheets("AutoInput").Move Befo=Sheets(1)
Sheets("AutoInput").Select

' Dim p As Integer
p = 2

For I = 1 To Sheets.Count
Sheets(I).Select
GoSub DoCopy
Next I

Exit Sub

DoCopy:

If Cells(1, 1) = "Sub-Contract Payment" Then ' If A1 = LO Template
then:
' Test for name in box &
link through if so
' for per subcontractor.
'Module3.PartOne (p)
'Module4.PartTwo (p)
'Module5.PartThree (p)
'Module6.PartFour (p)
'Module7.PartFive (p)

Call PartOne
Call PartTwo
Call PartThree
Call PartFour
Call PartFive

End If

Return

End Sub

For some reason the I variable is not picked up by the other modules. I
have declared I & p as public in these modules. I am stuck.

Please help!

Thanks,
Tom

--
tomjermy
------------------------------------------------------------------------
tomjermy's Profile: http://www.excelforum.com/member.php...o&userid=24666
View this thread: http://www.excelforum.com/showthread...hreadid=574197


--

Dave Peterson
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
Private modules and global variables davidm Excel Programming 6 November 25th 05 07:10 PM
Passing Variables Jeff Excel Discussion (Misc queries) 1 November 4th 05 06:46 PM
Help please! Loops? For Each? Variables? Roger Excel Programming 2 April 27th 05 01:17 PM
Passing Variables Tom Ogilvy Excel Programming 0 July 23rd 04 04:19 PM
Passing Variables Royce[_2_] Excel Programming 1 November 20th 03 02:16 PM


All times are GMT +1. The time now is 03:04 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"