Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Calling an Object using variables (What am I doing wrong????)

I was wondering if someone out there might know how I would be able to
do the following:

I have 3 ComboBoxes and 3 Labels that are named as follows

Label_1
Label_2
Label_3

ComboBox_1
ComboBox_2
ComboBox_3

I am trying to create a subroutine to go through a loop from 1-3 and
hide both the comboboxes and labels, but for some reason I can not use
variables to call an object. Any ideas how I could make this work?


here is my subroutine so far


sub removeitems ()

dim counter as integer
dim tag1 as string
dim tag2 as string
dim ctl as control

counter = 1
tag1 = "ComboBox_"
tag2 = "Label_"

do until counter = 3

ctl = tag1 & counter (I have also tried using Set ctl =)
ctl.visible = false
ctl = tag2 & counter
ctl.visible = false

counter = counter + 1

loop

end sub

*** Sent via Developersdex http://www.developersdex.com ***
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 35,218
Default Calling an Object using variables (What am I doing wrong????)

Controls on a userform?

Dim iCtr as long
for ictr = 1 to 3
me.controls("label_" & ictr).visible = false
me.controls("combobox_" & ictr).visible = false
next ictr

Superman wrote:

I was wondering if someone out there might know how I would be able to
do the following:

I have 3 ComboBoxes and 3 Labels that are named as follows

Label_1
Label_2
Label_3

ComboBox_1
ComboBox_2
ComboBox_3

I am trying to create a subroutine to go through a loop from 1-3 and
hide both the comboboxes and labels, but for some reason I can not use
variables to call an object. Any ideas how I could make this work?

here is my subroutine so far

sub removeitems ()

dim counter as integer
dim tag1 as string
dim tag2 as string
dim ctl as control

counter = 1
tag1 = "ComboBox_"
tag2 = "Label_"

do until counter = 3

ctl = tag1 & counter (I have also tried using Set ctl =)
ctl.visible = false
ctl = tag2 & counter
ctl.visible = false

counter = counter + 1

loop

end sub

*** Sent via Developersdex http://www.developersdex.com ***


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Calling an Object using variables (What am I doing wrong????)


Thank you very much for your help. That seems to do the trick.

*** Sent via Developersdex http://www.developersdex.com ***
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
Not at all clear on use of variables and/or object variables JMay-Rke Excel Discussion (Misc queries) 11 July 4th 08 06:36 PM
Calling subroutines and passing variables matpj[_56_] Excel Programming 0 March 29th 06 03:55 PM
Calling Macro - Will it take variables? Andibevan[_2_] Excel Programming 3 June 14th 05 03:28 PM
Calling the wrong macro Philip[_6_] Excel Programming 4 October 25th 04 07:04 PM
calling windows with variables Paul Excel Programming 3 August 2nd 04 04:49 AM


All times are GMT +1. The time now is 01:35 PM.

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"