Solved

Dynamic UserForm – Change Non-Active Command Button Color

Posted on 2014-09-09
2
262 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 50

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Article by: Leon
Software Metering within our group of companies has always been an afterthought until auditing of software and licensing became a pain point. Orchestrator and SCCM metering gave us the answer and it was an exciting process.
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
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…

830 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