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!
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.
so run it from a (in ThisWorkbook)
Code:
Private Sub Workbook_Open()
ClassBox_Change
End Sub
 
Upvote 0
in general you use sheets for macros that directly only operate with the code. workbook or module for multiuse code
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,223,893
Messages
6,175,239
Members
452,621
Latest member
Laura_PinksBTHFT

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top