string variable as object name problem

IanJG

New Member
Joined
Jul 17, 2014
Messages
18
Hi
Am i missing something
The label names are comp1label, comp2label, etc
The msgbox gives the correct name but applying the caption does not?
thanks for you help

Private Sub refreshbutton1_Click()
Dim i As Integer
Dim qL As String

For i = 1 To 9
qL = "comp" & (i) & "label"
MsgBox qL
With qL
.Caption = "hope for success"
End With
Next i
end sub
 
You can't use a string as an object. If the controls are on a userform you can use:
Code:
With Me.Controls(qL)
 
Upvote 0

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