Solved

Dynamic UserForm – Change Non-Active Command Button Color

Posted on 2014-09-09
2
255 Views
Last Modified: 2014-09-10
I have a dynamic UserForm where the user answers each question by clicking on the appropriate command button.  

Upon clicking on the command button, the class module for the event changes the backcolor to a darker color to highlight the selection.  

If the user then changes his/her answer, how do I reset the backcolor of the non-active command buttons for a given question?

I have attached the userform, as well as screenshots.
Questionnaire-2.xlsm
Questionnaire-Screenshot.docx
0
Comment
Question by:Quiver
2 Comments
 
LVL 49

Accepted Solution

by:
Rgonzo1971 earned 500 total points
ID: 40313828
Hi,

Pls try

Private Sub cmd_Click()
    Dim ClassRowNum As Integer
    Dim TagValue As String
    Dim TestCaption As String
    Dim ws_cell_cnt As Integer
    Dim ws_cell As String
    Dim ctrl
   'find the current row to enter data onto the worksheet
    ClassRowNum = Sheets("Main").UsedRange.Rows.Count
    

    TagValue = Me.cmd.Tag
    TestCaption = Me.cmd.Caption
    
    For ws_cell_cnt = 3 To 5
       ws_cell = Sheets("Test_Answers").Cells(2, ws_cell_cnt)
        
       If ws_cell = TagValue Then
          Sheets("Test_Answers").Cells(ClassRowNum, ws_cell_cnt).Value = TestCaption
            For Each ctrl In UserForm1.Controls
                If ctrl.Tag = TagValue Then
                    If TestCaption = ctrl.Caption Then
                        Me.cmd.BackColor = &H80C0FF
                    Else
                    ctrl.BackColor = &HC0E0FF
                    End If
                End If
            Next
        End If
       
    Next ws_cell_cnt
 
End Sub

Open in new window

Regards
0
 

Author Closing Comment

by:Quiver
ID: 40314051
Thank you so much!  It is just the code I needed.  Obviously, I still have a lot to learn but it is nice to know that there are people like you on Experts Exchange that are able and willing to help (and so quickly!).  Thanks again!
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel VBA 10 40
excel 2016 program to loop through scripts to apply filename 2 21
Generate a certain future date depending on current cell date. 15 29
And OR formula 5 22
The new Microsoft OS looks great, is easier than ever to upgrade to, it is even free.  So what's the catch?  If you don't change the privacy settings, Microsoft will, in accordance with the (EULA) you clicked okay to without reading, collect all the…
Excel can be a tricky bit of software to get your head around. Whilst you’ll be able to eventually get to grips with the basic understanding of how to get by, there are a few Excel tips that not everybody will even know about let alone know how to d…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question