Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default How to refer to controls by string

Is there anyway to use a control's string name to manipulate it?
At the moment, I have a lot of controls named in a handy manner
("Combobox_A1", "ComboBox_B2", etc.)
I often need to be able to change the box based on the "A1" identifier.
At the moment, I'm using a loop as follows

For each Ctrl in MyForm.Controls
If (right(ctrl.name,2) = "A1" then
ctrl.value = whatever

But it would be nice to simply use the "A1", build the string "Combobox_A1"
and then say
Control("Combobox_a1").Value = whatever

What's the syntax for this?

Darren



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,236
Default How to refer to controls by string

Darren,

You were nearly there.

MyForm.Controls("Combobox_a1").Value = whatever

You're probably able to omit the MyForm.

Rob



"Darren Hill" wrote in message
...
Is there anyway to use a control's string name to manipulate it?
At the moment, I have a lot of controls named in a handy manner
("Combobox_A1", "ComboBox_B2", etc.)
I often need to be able to change the box based on the "A1" identifier.
At the moment, I'm using a loop as follows

For each Ctrl in MyForm.Controls
If (right(ctrl.name,2) = "A1" then
ctrl.value = whatever

But it would be nice to simply use the "A1", build the string

"Combobox_A1"
and then say
Control("Combobox_a1").Value = whatever

What's the syntax for this?

Darren





  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default How to refer to controls by string

Put an "s" on Control
Userform1.Controls("Combobox_a1").Value

should work

mval = "A1"
Controls("Combobox_" & mval).Value = "ABCD"

would also be another example.

--
Regards,
Tom Ogilvy

Darren Hill wrote in message
...
Is there anyway to use a control's string name to manipulate it?
At the moment, I have a lot of controls named in a handy manner
("Combobox_A1", "ComboBox_B2", etc.)
I often need to be able to change the box based on the "A1" identifier.
At the moment, I'm using a loop as follows

For each Ctrl in MyForm.Controls
If (right(ctrl.name,2) = "A1" then
ctrl.value = whatever

But it would be nice to simply use the "A1", build the string

"Combobox_A1"
and then say
Control("Combobox_a1").Value = whatever

What's the syntax for this?

Darren





  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default How to refer to controls by string

Thanks, Tom and Rob. I was pretty close wasn't I? )

--
Darren


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
Change 3 letter text string to a number string Pete Excel Discussion (Misc queries) 3 December 31st 07 07:47 PM
Using a txt string to refer to other work book CC-Khriz Excel Worksheet Functions 0 January 26th 06 01:20 PM
ActiveX Controls vs Form Controls Alex Excel Discussion (Misc queries) 1 January 11th 06 08:46 AM
to search for a string and affect data if it finds the string? Shwaman Excel Worksheet Functions 1 January 11th 06 12:56 AM
Create a formula into a String then assign string to a cell Myrna Larson[_2_] Excel Programming 6 August 23rd 03 09:42 PM


All times are GMT +1. The time now is 10:16 AM.

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

About Us

"It's about Microsoft Excel"