VBA - Case study whether a subroutine is active or not.

prinzip

New Member
Joined
Feb 7, 2012
Messages
34
Hello, I started using VBA recently and I have a question. I am using the case study shown below in a UserForm.

Code:
        Case 0: Call ActivateHDB
        Case 1: Call ActivateHDT
        Case 2: Call ActivateLD4C
        Case 3: Call ActivateLD4T
        Case 4: Call ActivateM4
        Case 5: Call ActivateLD2
Through a different subroutine named ActivateGAS (shown below) and called after the above select case option, i want to perform an If...else If case structure ( I think that is the most appropriate). Maybe its a stupid question, but I don't know how to find out whether a subroutine is active or not.

Code:
Sub ActivateGAS()

    With wb1
        Selection.Rows(5).Select
    End With
    
    With wb2
    
        If IsActivated.ActivateLD4C Then
        Selection.Rows("1:7").Select
        ElseIf IsActivated.ActivateLD4T Then
        Selection.Rows("1:7").Select
        Else
        Selection.Rows("1:4").Select
        End If
        
    End With
    
End Sub
The IsActivated command its just something i made up my mind to show what I'm looking for.
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Welcome to MrExcel.

Can't you use the same Cases in ActivateGAS?

Cases seem to work but i get an Object variable or With block variable not set. How is this fixed?

Userform code:
Code:
Option Explicit

Private Sub cmdCancel_Click()

    Unload Me
    
End Sub

Private Sub cmdConfirm_Click()

    Select Case ComboBox2.ListIndex
 
        Case -1
            MsgBox "Select vehicle"
            Exit Sub
     
        Case 0: Call ActivateHDB
        Case 1: Call ActivateHDT
        Case 2: Call ActivateLD4C
        Case 3: Call ActivateLD4T
        Case 4: Call ActivateM4
        Case 5: Call ActivateLD2
        
    End Select
End sub

Module:
Code:
Option Explicit
Dim ComboBox2 As ComboBox

Sub ActivateGSL()

    wb1.Activate
    With wb1
        Selection.Rows(3).Select
    End With
    
    wb2.Activate
    With wb2
        Select Case ComboBox2.ListIndex
 
        Case 0: Selection.Rows("5:8").Select
        Case 1: Selection.Rows("5:8").Select
        Case 2: Selection.Rows("8:14").Select
        Case 3: Selection.Rows("8:14").Select
        Case 4: Selection.Rows("5:8").Select
        Case 5: Selection.Rows("5:8").Select
        
        End Select
    End With

End Sub
 
Upvote 0
Is your ActivateGSL procedure in the same module as the procedure that calls it?

No, the ActivateGSL is in Module code and the procedure that originally calls it is in a UserForm code. Do i have to state the Select case options in the module as well?
 
Upvote 0
If you want to access the controls on the UserForm it's easiest to put the code in the Userform's module.

It worked Andrew, thx.

Theoretically spoken, is there any occasion that it might be required to have two separate codes (UserForm code and Module code)? Is there any solution to that case?
 
Upvote 0

Forum statistics

Threads
1,223,227
Messages
6,170,848
Members
452,361
Latest member
d3ad3y3

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