For...Next Loop doesn't work in UserForm

BluEEyE86

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

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 for your help.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Maybe something like this? ThisWorkbook.Worksheets("Skill_matrix_SQA").Range (A13) serves no purpose here.
VBA Code:
Option Base 1

Sub Test()

Dim m As Byte
Dim S(1 To 23) As String
Dim Label(1 To 23) 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

End Sub
 
Upvote 0
Are you actually doing anything with those cell values other than trying to use them as label captions?
 
Upvote 0
There are no changes. I want to use those cells exactly as Label Captions. If the desription insde the cell would change, Label captio would be changed as well. This the idea.
 
Upvote 0
You can't link them dynamically, but it doesn't look like you need the intermediate variables to me, so just:

VBA Code:
    For m = 1 To 23
      
        Me.Controls("Label" & m).Caption = ThisWorkbook.Worksheets("Skill_matrix_SQA").Cells(13, m + 3).Value
      
    Next m
 
  • Like
Reactions: Zot
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

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