Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Userform Label question

Hello,

I have a form which contains 10 labels, named Lb1 to Lb10. The form has
a combobox and a command button. What I would like to is each time the
command button is clicked the text in combobox is added to the labels.

I've tried the following but it doesnt work.
sub commandbutton_click()
dim count as integer
dim lablename as string

count = 1

lablename = CStr(count) ' I thought I would need to cast the variable

Lb & lablename.caption = cblist.text

count = count + 1

' I will need to create a loop so that the count stops at 10.
end sub

Also I'm sure there's a much better way to do this. Could you create an
array of label names then loop through them using count?

Any help as always greatly appreciated.

David
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default Userform Label question

sub commandbutton_click()
Static count as integer
dim lablename as string

if count = 0 then _
count = 1

if count 10 then
count = 1
lablename = CStr(count) ' I thought I would need to cast the variable

Userform1.Controls("Lb" & lablename).caption = cblist.text

count = count + 1
End Sub


or if you want the same value placed in all labels:


sub commandbutton_click()
Dim c count as integer
dim lablename as string

for count = 1 to 10

lablename = CStr(count) ' I thought I would need to cast the variable

Userform1.Controls("Lb" & lablename).caption = cblist.text

Next

End Sub

--
Regards,
Tom Ogilvy



"David Goodall" wrote in message
...
Hello,

I have a form which contains 10 labels, named Lb1 to Lb10. The form has
a combobox and a command button. What I would like to is each time the
command button is clicked the text in combobox is added to the labels.

I've tried the following but it doesnt work.
sub commandbutton_click()
dim count as integer
dim lablename as string

count = 1

lablename = CStr(count) ' I thought I would need to cast the variable

Lb & lablename.caption = cblist.text

count = count + 1

' I will need to create a loop so that the count stops at 10.
end sub

Also I'm sure there's a much better way to do this. Could you create an
array of label names then loop through them using count?

Any help as always greatly appreciated.

David



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default Userform Label question

Tom
Thank you very much.
David




Tom Ogilvy wrote:
sub commandbutton_click()
Static count as integer
dim lablename as string

if count = 0 then _
count = 1

if count 10 then
count = 1
lablename = CStr(count) ' I thought I would need to cast the variable

Userform1.Controls("Lb" & lablename).caption = cblist.text

count = count + 1
End Sub


or if you want the same value placed in all labels:


sub commandbutton_click()
Dim c count as integer
dim lablename as string

for count = 1 to 10

lablename = CStr(count) ' I thought I would need to cast the variable

Userform1.Controls("Lb" & lablename).caption = cblist.text

Next

End Sub

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
Userform Label Steve[_9_] Excel Discussion (Misc queries) 7 October 29th 07 09:51 PM
Userform blinking label Ed Excel Programming 2 July 17th 04 12:24 AM
UserForm label doesn't load? Ed[_18_] Excel Programming 4 June 21st 04 07:53 PM
UserForm Label & Format Problems Mark Driscol Excel Programming 5 April 14th 04 08:33 PM
Making a TextBox look and feel like a Label in a userform Harald Staff[_4_] Excel Programming 2 July 30th 03 08:35 PM


All times are GMT +1. The time now is 12:34 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"