Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Iterate through controls

Hi All

I have an excel worksheet with 36 comboboxes (plus some other controls). I
want to iterate through 35 of the comboboxes that have names such as D1T1,
D1T2, D1T3, D2T1, D2T2, D2T3 etc. As an example, let's say I want to clear
the contents of each:

dim d, t as integer
dim cboName as string
dim cbo as Control

for d = 1 to 7
for t = 1 to 5
cboName = "TS.D" & CStr(d) & "T" & CStr(t) 'TS.D1T1
with cbo(cboName) 'with TS.D1T1
.clear
end With
Next t
Next d

this code obviously doesn't work, but it gives you an idea of what I'm
trying to do. TS is the name of the worksheet with the controls.

TIA
Lee


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Iterate through controls

Perhaps this simplified example will help:

Sub Test()
Dim t As Integer, ctl As OLEObject, cboName As String
For Each ctl In Worksheets("TS").OLEObjects
For t = 1 To 3
cboName = "ComboBox" & t
If ctl.Name = cboName Then ctl.Object.Clear
Next t
Next
End Sub

--

Vasant

"lgbjr" wrote in message
...
Hi All

I have an excel worksheet with 36 comboboxes (plus some other controls). I
want to iterate through 35 of the comboboxes that have names such as D1T1,
D1T2, D1T3, D2T1, D2T2, D2T3 etc. As an example, let's say I want to clear
the contents of each:

dim d, t as integer
dim cboName as string
dim cbo as Control

for d = 1 to 7
for t = 1 to 5
cboName = "TS.D" & CStr(d) & "T" & CStr(t) 'TS.D1T1
with cbo(cboName) 'with TS.D1T1
.clear
end With
Next t
Next d

this code obviously doesn't work, but it gives you an idea of what I'm
trying to do. TS is the name of the worksheet with the controls.

TIA
Lee




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7
Default Iterate through controls

Vasant,

Thanks! Just a simple example gave me a push in the right direction.

Lee

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Perhaps this simplified example will help:

Sub Test()
Dim t As Integer, ctl As OLEObject, cboName As String
For Each ctl In Worksheets("TS").OLEObjects
For t = 1 To 3
cboName = "ComboBox" & t
If ctl.Name = cboName Then ctl.Object.Clear
Next t
Next
End Sub

--

Vasant

"lgbjr" wrote in message
...
Hi All

I have an excel worksheet with 36 comboboxes (plus some other controls).
I
want to iterate through 35 of the comboboxes that have names such as
D1T1,
D1T2, D1T3, D2T1, D2T2, D2T3 etc. As an example, let's say I want to
clear
the contents of each:

dim d, t as integer
dim cboName as string
dim cbo as Control

for d = 1 to 7
for t = 1 to 5
cboName = "TS.D" & CStr(d) & "T" & CStr(t) 'TS.D1T1
with cbo(cboName) 'with TS.D1T1
.clear
end With
Next t
Next d

this code obviously doesn't work, but it gives you an idea of what I'm
trying to do. TS is the name of the worksheet with the controls.

TIA
Lee






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default Iterate through controls

Thanks for the feedback, Lee; glad to help.

--

Vasant

"lgbjr" wrote in message
...
Vasant,

Thanks! Just a simple example gave me a push in the right direction.

Lee

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Perhaps this simplified example will help:

Sub Test()
Dim t As Integer, ctl As OLEObject, cboName As String
For Each ctl In Worksheets("TS").OLEObjects
For t = 1 To 3
cboName = "ComboBox" & t
If ctl.Name = cboName Then ctl.Object.Clear
Next t
Next
End Sub

--

Vasant

"lgbjr" wrote in message
...
Hi All

I have an excel worksheet with 36 comboboxes (plus some other

controls).
I
want to iterate through 35 of the comboboxes that have names such as
D1T1,
D1T2, D1T3, D2T1, D2T2, D2T3 etc. As an example, let's say I want to
clear
the contents of each:

dim d, t as integer
dim cboName as string
dim cbo as Control

for d = 1 to 7
for t = 1 to 5
cboName = "TS.D" & CStr(d) & "T" & CStr(t) 'TS.D1T1
with cbo(cboName) 'with TS.D1T1
.clear
end With
Next t
Next d

this code obviously doesn't work, but it gives you an idea of what I'm
trying to do. TS is the name of the worksheet with the controls.

TIA
Lee








Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Iterate Circular Reference Brandt Excel Discussion (Misc queries) 1 August 3rd 05 11:43 PM
Event procedures for controls added with Controls.Add John Austin[_4_] Excel Programming 1 March 9th 05 03:31 PM
Can't iterate thru a row with For peter Excel Programming 2 January 7th 05 04:46 AM
Iterate columns wired Excel Programming 9 November 14th 03 11:14 PM


All times are GMT +1. The time now is 01:40 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"