ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   using variable for a control name (https://www.excelbanter.com/excel-programming/294020-using-variable-control-name.html)

Mark Kubicki

using variable for a control name
 
can a variable be used as a control name?

Dim i As Integer
Dim cnDayLabel As Control 'or should this be as a String?

For i = 1 To 7
cnDayLabel = "DayLabel" & i
cnDayLabel.Visible = False
Next i



Bob Phillips[_6_]

using variable for a control name
 
Hi Mark,

If they are control toolbox con trols, use

Dim cnDayLabel As OLEObject 'or should this be as a String?

For i = 1 To 7
Set cnDayLabel = ActiveSheet.OLEObjects("DayLabel" & i)
cnDayLabel.Visible = False
Next i

If they forms controls, use

Dim i As Integer
Dim cnDayLabel As Shape

For i = 1 To 7
Set cnDayLabel = ActiveSheet.Shapes("DayLabel" & i)
cnDayLabel.Visible = False
Next i

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"mark kubicki" wrote in message
...
can a variable be used as a control name?

Dim i As Integer
Dim cnDayLabel As Control 'or should this be as a String?

For i = 1 To 7
cnDayLabel = "DayLabel" & i
cnDayLabel.Visible = False
Next i






All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com