Organize Code

8700Rakf

New Member
Joined
May 15, 2019
Messages
32
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!
 

mole999

Moderator
Joined
Oct 23, 2004
Messages
9,878
so run it from a (in ThisWorkbook)
Code:
Private Sub Workbook_Open()
ClassBox_Change
End Sub
 

mole999

Moderator
Joined
Oct 23, 2004
Messages
9,878
in general you use sheets for macros that directly only operate with the code. workbook or module for multiuse code
 

shg

MrExcel MVP
Joined
May 7, 2008
Messages
21,678
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.
 

Forum statistics

Threads
1,077,849
Messages
5,336,734
Members
399,100
Latest member
darcob

Some videos you may like

This Week's Hot Topics

Top