Solved

Dynamic UserForm – Change Non-Active Command Button Color

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

Accepted Solution

by:
Rgonzo1971 earned 500 total points
Comment Utility
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
Comment Utility
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

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
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.
The viewer will learn how to simulate a series of coin tosses with the rand() function and learn how to make these “tosses” depend on a predetermined probability. Flipping Coins in Excel: Enter =RAND() into cell A2: Recalculate the random variable…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…

762 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now