help with vba code for an interface

aiman015

New Member
Joined
May 18, 2020
Messages
2
Office Version
  1. 2010
Platform
  1. Windows
hello guys,
actually i am trying to make an interface for my workbook, and i started making it using vba, but i got stuck.
FIRST: in "what do you want to do" section i want to print two possibilities : consumption and KPI.
then if the user choose consumption,
-->the second part "what kind of energy"print 3 possibilities (electricity,water,gaz)
if else the user choose KPI,
--> "what kind of energy" print 3 other possibilities (KPI1,KPI2,KPI3)
Finally: each choice needs to be related to a worksheet, and send the user directly to that sheet named electricity or KPI1...etc by using the button "validate".
the problem is i tried so many codes, but it didn't work.
thanks a lot
 

Attachments

  • mrexcel.PNG
    mrexcel.PNG
    9.2 KB · Views: 3

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.
With 2 ComboBoxes ..
Combobox1 (What do you want to do?)
Combobox2 (What Kind of Energy?)
And 2 command buttons ..
CommandButton1 (Validate)
CommandButton2 (Reset)

VBA Code:
Private Sub UserForm_Initialize()
    ComboBox1.SetFocus
End Sub
Private Sub ComboBox1_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    ComboBox1.List = Array("Consumption", "KPI")
    ComboBox1.DropDown
End Sub
Private Sub ComboBox1_Change()
    ComboBox2.SetFocus
End Sub
Private Sub ComboBox2_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)
    Select Case ComboBox1.Text
        Case vbNullString
            ComboBox1.SetFocus
        Case "Consumption"
            ComboBox2.List = Array("Electricity", "Water", "Gaz")
            ComboBox2.DropDown
        Case "KPI"
            ComboBox2.List = Array("KPI1", "KPI2", "KPI3")
            ComboBox2.DropDown
    End Select
End Sub
Private Sub CommandButton1_Click()
'Validate Button code
   Sheets(ComboBox2.Text).Activate
   Unload Me
End Sub
Private Sub CommandButton2_Click()
'Reset Button code
    ComboBox1.Value = ""
    ComboBox2.Value = ""
End Sub
 
Upvote 0
Cross posted vba code for an interface

While we do allow Cross-Posting on this site, we do ask that you please mention you are doing so and provide links in each of the threads pointing to the other thread (see rule 13 here along with the explanation: Forum Rules). This way, other members can see what has already been done in regards to a question, and do not waste time working on a question that may already be answered.
 
Upvote 0

Forum statistics

Threads
1,215,325
Messages
6,124,252
Members
449,149
Latest member
mwdbActuary

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