Results 1 to 6 of 6

Thread: Organize Code
Thanks Thanks: 0 Likes Likes: 0

  1. #1
    New Member
    Join Date
    May 2019
    Posts
    19
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Organize Code

    So, right now I have a functioning code, good or bad one, but what I want to know, is the following:

    • How can split the code up in sections, so I have a better overview? Right now I have one long code, which makes hard to go through.
    • How Can i manage the code, so that I begins as soon as i open the workbook.


    My code so fare:

    Code:
    Private Sub ClassBox_Change()
    
    
    
    
     Select Case VersionBox
    
    
     Case "OIML R51 1996 (Old EU)"
        Select Case ClassBox
            Case "Y(a)"
            ScaleIntervalBox.Clear
            Me.ScaleIntervalBox.AddItem "Single"
        End Select
    
    
     Case "OIML R51 2006 (New EU)"
        Select Case ClassBox
        Case "Y(a)"
            ScaleIntervalBox.Clear
            Me.ScaleIntervalBox.AddItem "Single"
            Me.ScaleIntervalBox.AddItem "Multi"
        Case "Y(b)"
            ScaleIntervalBox.Clear
            Me.ScaleIntervalBox.AddItem "Single"
        End Select
     Case "NMIA (AU)"
      Select Case ClassBox
            Case "Y(a)"
            ScaleIntervalBox.Clear
            Me.ScaleIntervalBox.AddItem "Single"
        End Select
    
    
     Case "NIST (US)"
      Select Case ClassBox
            Case "Class III"
            ScaleIntervalBox.Clear
            Me.ScaleIntervalBox.AddItem "Single"
        End Select
     End Select
    
    
    End Sub
    
    
    
    
    
    
    Private Sub Worksheet_Activate()
        Dim Versions As Variant
        Dim Typen As Variant
        Dim ScaleI As Variant
        Dim Unit As Variant
        Dim Weight As Variant
    
    
    
    
        Versions = Array("OIML R51 1996 (Old EU)", "OIML R51 2006 (New EU)", "NMIA (AU)", "NIST (US)")
        Typen = Array("Post Scale", "Scale")
        ScaleI = Array("Single", "Multi")
        Unit = Array("g", "kg", "Lb")
        Weight = Array(1000, 10000, 15000, 20000, 30000, 35000, 40000, 45000, 50000)
    
    
         With Me.VersionBox
            .Clear
            .List = Versions
         End With
    
    
         With Me.TypeBox
            .Clear
            .List = Typen
         End With
    
    
    
         With Me.UnitBox
            .Clear
            .List = Unit
         End With
    
    
         With Me.WeightBox
            .Clear
            .List = Weight
         End With
    
    
    End Sub
    Thanks in advance!

  2. #2
    Moderator mole999's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    9,694
    Post Thanks / Like
    Mentioned
    15 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Organize Code

    so run it from a (in ThisWorkbook)
    Code:
    Private Sub Workbook_Open()
    ClassBox_Change
    End Sub
    • Yes I know there are better ways to do it. I just wish I knew them. - 97, 2003, 2007, 2010, 2013, 2016 & 2019
    • I wear my ignorance openly, excel is not my chosen career, its a means to an ends
    • Posting Guidelines Want to post well laid out questions and answers Translate Excel Versions
      Code:
      [CODE ]Put Your Code[/ CODE]
    • Settings > General Settings (on the left) scroll to the bottom, > Miscellaneous Options > Use ENHANCED
    • X-Posting Guidelines Rule 13 > CHART STUFF

  3. #3
    New Member
    Join Date
    May 2019
    Posts
    19
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Organize Code

    So du you just put the code into a module or what do you mean??

  4. #4
    Moderator mole999's Avatar
    Join Date
    Oct 2004
    Location
    UK
    Posts
    9,694
    Post Thanks / Like
    Mentioned
    15 Post(s)
    Tagged
    1 Thread(s)

    Default Re: Organize Code

    in general you use sheets for macros that directly only operate with the code. workbook or module for multiuse code
    • Yes I know there are better ways to do it. I just wish I knew them. - 97, 2003, 2007, 2010, 2013, 2016 & 2019
    • I wear my ignorance openly, excel is not my chosen career, its a means to an ends
    • Posting Guidelines Want to post well laid out questions and answers Translate Excel Versions
      Code:
      [CODE ]Put Your Code[/ CODE]
    • Settings > General Settings (on the left) scroll to the bottom, > Miscellaneous Options > Use ENHANCED
    • X-Posting Guidelines Rule 13 > CHART STUFF

  5. #5
    New Member
    Join Date
    May 2019
    Posts
    19
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Default Re: Organize Code

    Sorry, but i still dont understand the concept

  6. #6
    MrExcel MVP shg's Avatar
    Join Date
    May 2008
    Location
    The Great State of Texas
    Posts
    21,496
    Post Thanks / Like
    Mentioned
    0 Post(s)
    Tagged
    13 Thread(s)

    Default Re: Organize Code

    ThisWorkbook, sheet modules, and forms module are all class modules.

    ThisWorkbook module must contain the procedures triggered by workbook events. If they're not there, they won't run. For the same reason,

    o sheet modules must contain the procedures triggered by sheet events

    o form modules must contain the procedures triggered by form events

    o class modules must contain the procedures triggered by class events

    In general, everything else goes in standard code modules.

Some videos you may like

User Tag List

Tags for this Thread

Like this thread? Share it with others

Like this thread? Share it with others

Posting Permissions

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