Solved

Dynamic UserForm – Change Non-Active Command Button Color

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

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

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…
This article descibes how to create a connection between Excel and SAP and how to move data from Excel to SAP or the other way around.
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

737 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