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!
 

Some videos you may like

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.

mole999

Moderator
Joined
Oct 23, 2004
Messages
10,099
Office Version
2019, 2016, 2013
Platform
Windows
so run it from a (in ThisWorkbook)
Code:
Private Sub Workbook_Open()
ClassBox_Change
End Sub
 

mole999

Moderator
Joined
Oct 23, 2004
Messages
10,099
Office Version
2019, 2016, 2013
Platform
Windows
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,736
Office Version
2010
Platform
Windows
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,089,313
Messages
5,407,514
Members
403,150
Latest member
stellalol

This Week's Hot Topics

  • help please
    SORRY NOT ANY GOOD AT EXCEL SO HELP WOULD BE MUCH APPRECIATED this formula is in a sheet called ignore...
  • two formulas needed
    Hello, I'll try my best to explain this: First formula needed in Sheet1 cell A2: If Sheet1 cell B2 = Sheet2 cell B2 then return a 1. If not then...
  • Dynamic Counts
    Good afternoon, we are tidying up some data & the data seems to be growing quicker than we are tidying it up! What we confirm (by reviewing it...
  • Help Excel formula eliminate duplicate values and keep only 2 identical rows.
    as picture below column A has a duplicate value. but the values are not the same as the rule. sometimes 4 rows, sometimes 10 rows or 7 or 9...
  • Macro Compile Error Sub or Function not defined
    Hello, I am trying to run macros from a validation list, all macros have been created and run perfectly on there own but I'm getting a compile...
  • Last row combined with Current Region VBA
    I'm generally happy finding the last row of data through something like Lastrow = Cells(Rows.Count, "D").End(xlUp) but I don't always receive data...
Top