+ Reply to Thread
Results 1 to 11 of 11

Calling Sub from Array!

  1. #1
    Registered User
    Join Date
    10-07-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    30

    Calling Sub from Array!

    Please Login or Register  to view this content.
    This code give me an "Compile Error: Expected Sub, Function, or Property". I had tried many ways but they no work also. Anyone can help me please?

  2. #2
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Calling Sub from Array!

    Replace the Call with Msgbox


    If your problem is solved, then please mark the thread as SOLVED>>Above your first post>>Thread Tools>>
    Mark your thread as Solved


    If the suggestion helps you, then Click *below to Add Reputation

  3. #3
    Registered User
    Join Date
    10-07-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Calling Sub from Array!

    Hi sixthsense, thanks for your help.

    But "Machine1" is a macro, I wanna call the macro instead of show them as a message.

    Please Login or Register  to view this content.
    There are couple of code in this subroutines, how can I call them? Or is that others code to trigger the macro in array?

  4. #4
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Calling Sub from Array!

    Just define this In the Top Line of the Module (i.e.) in the first line of the module code

    Dim test(1 To 3, 1 To 2) As Variant

    So that it can be used in any of the procedures of that module

  5. #5
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Calling Sub from Array!

    @sianjialin,

    you need to do this.

    Please Login or Register  to view this content.
    Happy Computing ,

    Xlbiznes.

    To show your appreciation please click *

  6. #6
    Registered User
    Join Date
    10-07-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Calling Sub from Array!

    do you meant to add the code Dim test(1 to 3, 1 to 2) as Variant into all the module to be call?

    Please Login or Register  to view this content.
    Is this what you mean?..If so, it doesn't work also

  7. #7
    Registered User
    Join Date
    10-07-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Calling Sub from Array!

    hi xlbiznes,

    I have try it but another error appear, I don't know how to solve it as I'm a beginner, sorry about that. The error message is as:

    Run-Time error '1004': Cannot run the macro 'Machine1'. the macro may not be available in this workbook or all macros may be disabled.

    What should I do? >_<

  8. #8
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Calling Sub from Array!

    You macro needs to be inside a module.

    To add a module :

    a) Click Developer
    b) Click Visual Basic
    c) Click Insert and then Click Module

  9. #9
    Registered User
    Join Date
    10-07-2013
    Location
    Malaysia
    MS-Off Ver
    Excel 2010
    Posts
    30

    Re: Calling Sub from Array!

    Yes, it is inside a module.

    Sub Machine1() in Module1, I think no problem for this.

  10. #10
    Valued Forum Contributor xlbiznes's Avatar
    Join Date
    02-22-2013
    Location
    Bahrain
    MS-Off Ver
    Excel 2007
    Posts
    1,223

    Re: Calling Sub from Array!

    Surprising,

    this runs perfectly, when i test it . Anyways take a look at this.
    Attached Files Attached Files

  11. #11
    Forum Guru :) Sixthsense :)'s Avatar
    Join Date
    01-01-2012
    Location
    India>Tamilnadu>Chennai
    MS-Off Ver
    2003 To 2010
    Posts
    12,770

    Re: Calling Sub from Array!

    Read this....

    Module Scope

    Module scope means that a variable can be declared before and outside of any procedure in a regular code module. If you use Private or Dim to declare the variable, only procedures that are in the same module can access that variable. Since a module level variable is not part of any procedure, it will retain its value even after the procedure that changes its value has terminated. For example,

    Dim ModVar As Long
    The variable ModVar can be read or changed from any procedure in the same module as the declaration. However, it cannot be accessed from a procedure that resides in another module. Separate modules may declare variables with the same name (e.g., both Module1 and Module2 both can have a module-level variable named ModVar). Each module-level variable will be accessed by procedures within the same module. If both Module1 and Module2 have a module-level variable named ModVar, procedures within Module1 will access the variable ModVar defined within Module1 and procedures within Module2 will access the variable ModVar defined in Module2. Variables with the same name in separate modules are completely independent of one another, even though they have the same name.

    You can use either Dim or Private to declare a module level variable that is accessible only within that module. That is, the following declarations are functionally equivalent.

    Dim ModVar As Long
    Private ModVar As Long

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] calling nth element in an array to be used in another code
    By vick2075 in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-04-2013, 10:48 AM
  2. Replies: 1
    Last Post: 04-19-2012, 04:37 AM
  3. calling function, returning one element of the array
    By petca059 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-02-2010, 04:50 AM
  4. Lets XLL function believe I am calling it from an array formula
    By toto_fr_2002 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-25-2010, 06:16 PM
  5. calling/using an array
    By Hein in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 04-15-2009, 07:13 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1