Change color of CommandButtons in a Loop in UserForm

BluEEyE86

New Member
Joined
May 25, 2021
Messages
34
Office Version
  1. 365
Platform
  1. Windows
Hello,

I'd like to make this kind of template in USerForm

Skills.PNG


I'm writing code to change CommandButton color based on excel cell. CommandButton color will be the same like excell's cell color. I', able to do it one by one as below just for few buttons with number 1:

VBA Code:
If ThisWorkbook.Worksheets("Skill_matrix_laboratorium").Cells(17, 4).Interior.Color = RGB(255, 255, 0) Then 'BHP
               
                    CommandButton4.BackColor = RGB(255, 255, 0)
                                
                Else: CommandButton4.BackColor = RGB(255, 255, 255)
            
            End If
    
            If ThisWorkbook.Worksheets("Skill_matrix_laboratorium").Cells(17, 7).Interior.Color = RGB(255, 255, 0) Then 'PPOŻ
               
                    CommandButton8.BackColor = RGB(255, 255, 0)
                                
                Else: CommandButton8.BackColor = RGB(255, 255, 255)
            
            End If

           If ThisWorkbook.Worksheets("Skill_matrix_laboratorium").Cells(17, 10).Interior.Color = RGB(255, 255, 0) Then
               
                   CommandButton12.BackColor = RGB(255, 255, 0)
                                
                Else: CommandButton12.BackColor = RGB(255, 255, 255)
            
           End If

I'm tryinf to do it in a loop but still have a problems like Buttons aren't marked or even UserForm isn't show.

VBA Code:
For i = 1 To 72 Step 3
                    If ThisWorkbook.Worksheets("Skill_matrix_laboratorium").Cells(17, i).Interior.Color = RGB(255, 255, 0) Then
                        Select Case i
                            Case i = 4
                                ommandButton4.BackColor = RGB(255, 255, 0)
                            Case i = 7
                                CommandButton8.BackColor = RGB(255, 255, 0)
                            Case i = 10
                                CommandButton12.BackColor = RGB(255, 255, 0)
                        End Select
                    End If
                Next i

Can someone help me how to do it in a loop ?
 
Hello,

I don't want to create new topic regarding this or should I do it ? Can some help me why below Loop doesn't work ? Numbering of "Labels" in UserForm is the same like numbering of "S" varabiles.

VBA Code:
Dim m As Byte

Dim S1 As String
Dim S2 As String
Dim S3 As String
Dim S4 As String
Dim S5 As String
Dim S6 As String
Dim S7 As String
Dim S8 As String
Dim S9 As String
Dim S10 As String
Dim S11 As String
Dim S12 As String
Dim S13 As String
Dim S14 As String
Dim S15 As String
Dim S16 As String
Dim S17 As String
Dim S18 As String
Dim S19 As String
Dim S20 As String
Dim S21 As String
Dim S22 As String
Dim S23 As String

ThisWorkbook.Worksheets("Skill_matrix_SQA").Range (A13)
  
    For m = 1 To 23
   
        S(m) = ThisWorkbook.Worksheets("Skill_matrix_SQA").Cells(13, m + 3).Value
       
        Label(m) = S(m)
       
    Next m

I have below error when try to run this code

Skills.PNG


Thanks your help.
 
Upvote 0

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
That is a totally different question so needs a new topic please.
 
Upvote 0

Forum statistics

Threads
1,215,767
Messages
6,126,773
Members
449,336
Latest member
p17tootie

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top