Solved

Dynamic UserForm – Change Non-Active Command Button Color

Posted on 2014-09-09
2
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 51

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

Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

Question has a verified solution.

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

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

734 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