Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2015
    Posts
    4

    Unanswered: Multiple functions for a command button in excel

    Hi guys.

    Im bit of a beginner with VBA. Im working with this workbook where I want a command button to have two functions. I now have two different buttons, but I want to have both functions for only one button, kinda merge the following two scripts into one:

    Private Sub CommandButton21_Click()
    Set cb = Ark1.CommandButton21
    With Ark2.Range("F3")
    If .Value = "God" Then
    cb.BackColor = RGB(255, 0, 0)
    ElseIf .Value = "Meget God" Then
    cb.BackColor = RGB(0, 255, 0)
    ElseIf .Value = "Mindre God" Then
    cb.BackColor = RGB(0, 0, 255)
    ElseIf .Value = "Ikke tilfredsstillende" Then
    cb.BackColor = RGB(100, 45, 150)
    End If
    End With
    End Sub



    Private Sub CommandButton22_Click()
    ThisWorkbook.Sheets("Ark2").Select
    End Sub

    Any ideas?

    B/R,
    Espen

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Code:
    Private Sub a()
        MsgBox("a");
    End Sub
    
    Private Sub b()
        MsgBox("b");
    End Sub
    Combined:
    Code:
    Private Sub a()
        MsgBox("a");
        MsgBox("b");
    End Sub
    Obviously the order in which the code gets combined makes a difference (A before B or B before A?).
    George
    Home | Blog

  3. #3
    Join Date
    Feb 2015
    Posts
    4

    Thanks

    Thank you very much for your reply, George !

    BR,
    Espen

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •