Consulting

Results 1 to 3 of 3

Thread: Solved: Calling Subs::Error "Compile Error: Expected Variable or Procedure, Not Module"

  1. #1

    Solved: Calling Subs::Error "Compile Error: Expected Variable or Procedure, Not Module"

    Okay then! The problem is: I really don't know what I am doing


    I am trying to break up one really long Sub into Modules, and then just call them.

    The user should click on a Button in the Spreadsheet:

    [VBA]Private Sub CommandButton1_Click()
    Call Main
    End Sub
    [/VBA]

    Which Calls "Main" module: (I think this is where the error comes up)

    [VBA]Public MyError_T As Double
    Public Percent As Double
    Public CI_WithinTen As Double
    Public MyMax_CI As Double
    Public MyMax_T As Double
    Public ErrorSquare_CI As Double
    Public ErrorSquare_T As Double
    Public BestCI_CFD As Worksheet
    Public BestCI_ISX As Worksheet
    Public DataAnalysis As Worksheet
    Public T_CFD As Worksheet
    Public T_ISX As Worksheet
    Public End_Error_CI_R As Long
    Public End_CI_R_Within5 As Long
    Public End_CI_R_Within5_10 As Long
    Public End_CI_R_Within10_20 As Long
    Public End_CI_R_Within20_30 As Long
    Public End_CI_R_Within30_40 As Long
    Public End_CI_R_Within40_50 As Long
    Public End_CI_R_Over50 As Long
    Public End_Error_CI_L As Long
    Public End_CI_L_Within5 As Long
    Public End_CI_L_Within5_10 As Long
    Public End_CI_L_Within10_20 As Long
    Public End_CI_L_Within20_30 As Long
    Public End_CI_L_Within30_40 As Long
    Public End_CI_L_Within40_50 As Long
    Public End_CI_L_Over50 As Long



    Sub Main()
    Call Initialize
    Call CI
    Call Temperature
    End Sub[/VBA]


    Calling Initialize:
    [VBA]Sub Initialize()


    Set BestCI_CFD = Worksheets("Best CI CFD")
    Set BestCI_ISX = Worksheets("Best CI ISX")
    Set T_CFD = Worksheets("Temp CFD")
    Set T_ISX = Worksheets("Temp ISX")
    Set DataAnalysis = Worksheets("Data Analysis")


    nRow = 25
    nCol = 50
    xgg = 0
    xgy = 0
    xgr = 0
    xyg = 0
    xyy = 0
    xyr = 0
    xrg = 0
    xry = 0
    xrr = 0
    G = 0
    Y = 0
    R = 0
    MyMax_CI = 0
    Percent = 0
    OverPredicted = 0
    CI_WithinTen = 0
    ErrorSquare_CI = 0
    ErrorSquare_T = 0

    Within5 = 0
    Within5_10 = 0
    Over10 = 0
    Counter = 0

    End_CI_R_Within5 = 0
    End_CI_R_Within5_10 = 0
    End_CI_R_Within10_20 = 0
    End_CI_R_Within20_30 = 0
    End_CI_R_Within30_40 = 0
    End_CI_R_Within40_50 = 0
    End_CI_R_Over50 = 0
    End_CI_L_Within5 = 0
    End_CI_L_Within5_10 = 0
    End_CI_L_Within10_20 = 0
    End_CI_L_Within20_30 = 0
    End_CI_L_Within30_40 = 0
    End_CI_L_Within40_50 = 0
    End_CI_L_Over50 = 0
    End Sub
    [/VBA]

    and so on...

  2. #2
    Got it!

    Can't have the modules that contain the Subs be named the same as the Subs themselves....

  3. #3
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    You call the Sub, not the module. If you have two identically named subs in different modules, you prefix with the module name so
    [vba]
    Call Initialize
    'or
    Call Main!Initialize
    [/vba]
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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