ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Call other sub in the same module (https://www.excelbanter.com/excel-programming/339722-call-other-sub-same-module.html)

yangyh[_4_]

Call other sub in the same module
 

Dear all,

I want to call other sub in the same module. Here are my codes. Can yo
help me point out the problem? Thanks.

Dim LibraryList(20) As String 'I want to use LibraryList(20) as
global array

Sub CreateLibraryArray()
Y = 0
For X = 1 To Worksheets.Count
If InStr(Sheets(X).Name, "Library") 0 Then
LibraryList(Y) = Sheet(X).Name
Y = Y + 1
End If
Next X
End Sub

Sub NewSub()
Dim List1(20) As String
CreateLibraryArray() 'Can I call CreateLibraryArray(
here?
List1(10) = LibraryList(10)
....
End Sub

Thanks.

Davi

--
yangy
-----------------------------------------------------------------------
yangyh's Profile: http://www.excelforum.com/member.php...fo&userid=2688
View this thread: http://www.excelforum.com/showthread.php?threadid=46657


Norman Jones

Call other sub in the same module
 
Hi David,

Your code worked for me with the following:

Change:

CreateLibraryArray()


to:

CreateLibraryArray

Also, change:

LibraryList(Y) = Sheet(X).Name


to:

LibraryList(Y) = Sheets(X).Name



---
Regards,
Norman



"yangyh" wrote in
message ...

Dear all,

I want to call other sub in the same module. Here are my codes. Can you
help me point out the problem? Thanks.

Dim LibraryList(20) As String 'I want to use LibraryList(20) as a
global array

Sub CreateLibraryArray()
Y = 0
For X = 1 To Worksheets.Count
If InStr(Sheets(X).Name, "Library") 0 Then
LibraryList(Y) = Sheet(X).Name
Y = Y + 1
End If
Next X
End Sub

Sub NewSub()
Dim List1(20) As String
CreateLibraryArray() 'Can I call CreateLibraryArray()
here?
List1(10) = LibraryList(10)
...
End Sub

Thanks.

David


--
yangyh
------------------------------------------------------------------------
yangyh's Profile:
http://www.excelforum.com/member.php...o&userid=26883
View this thread: http://www.excelforum.com/showthread...hreadid=466575





All times are GMT +1. The time now is 07:20 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com