Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Setting up a simple loop to fill labels?


Hi... been a while since i've posted here so Welcome back me!

I got a question for you all, I have about 30 labels on a userform an
I want my userform, on initilize, to fill those labels with values fro
the spreadsheet.

I'm hoping I can set up a small loop to do this and I guess my rea
question is How can I loop through 30 labels?

Would probably look like:

Dim LblName as object
dim i as integer


set lblName = userform.controls("label" & LblNumber)

for i = 1 to 30
lblname.*caption* = worksheets("sheet1").cells(1, *i*).value
next i



Any help would be great.. I have a lot of labels and a loop will mos
deffinatly help here

--
justchri
-----------------------------------------------------------------------
justchris's Profile: http://www.excelforum.com/member.php...nfo&userid=889
View this thread: http://www.excelforum.com/showthread.php?threadid=39802

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Setting up a simple loop to fill labels?

Maybe:

Private Sub UserForm_Initialize()
Dim lbl As Object
Dim i As Integer
i = 1
With Sheets("Sheet1")
For Each lbl In Me.Controls
If TypeName(lbl) = "Label" Then
lbl.Caption = .Cells(i, 1).Value
i = i + 1
End If
Next lbl
End With
End Sub

Hope this helps
Rowan

"justchris" wrote:


Hi... been a while since i've posted here so Welcome back me!

I got a question for you all, I have about 30 labels on a userform and
I want my userform, on initilize, to fill those labels with values from
the spreadsheet.

I'm hoping I can set up a small loop to do this and I guess my real
question is How can I loop through 30 labels?

Would probably look like:

Dim LblName as object
dim i as integer


set lblName = userform.controls("label" & LblNumber)

for i = 1 to 30
lblname.*caption* = worksheets("sheet1").cells(1, *i*).value
next i



Any help would be great.. I have a lot of labels and a loop will most
deffinatly help here.


--
justchris
------------------------------------------------------------------------
justchris's Profile: http://www.excelforum.com/member.php...fo&userid=8894
View this thread: http://www.excelforum.com/showthread...hreadid=398025


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Setting up a simple loop to fill labels?


awesome thank you... Ill see what i can do with it :cool

--
justchri
-----------------------------------------------------------------------
justchris's Profile: http://www.excelforum.com/member.php...nfo&userid=889
View this thread: http://www.excelforum.com/showthread.php?threadid=39802

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Setting up a simple loop to fill labels?


Ok, Im not sure what to do with this..

I have 10 cells on sheet1 a1:a10 that need to go into labels1 - 10

i have 15 cells on sheet1 c10:c25 that need to go into labels 11 -26

and so on. How can i change the code above to fit those needs

--
justchri
-----------------------------------------------------------------------
justchris's Profile: http://www.excelforum.com/member.php...nfo&userid=889
View this thread: http://www.excelforum.com/showthread.php?threadid=39802

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 226
Default Setting up a simple loop to fill labels?

How about:

Private Sub UserForm_Initialize()
Dim lbl As Object
Dim i As Integer
i = 1
With Sheets("Sheet1")
For Each lbl In Me.Controls
If TypeName(lbl) = "Label" Then
If i < 11 Then
lbl.Caption = .Cells(i, 1).Value
Else
lbl.Caption = .Cells(i - 1, 3).Value
End If
i = i + 1
End If
Next lbl
End With
End Sub

Regards
Rowan

"justchris" wrote:


Ok, Im not sure what to do with this..

I have 10 cells on sheet1 a1:a10 that need to go into labels1 - 10

i have 15 cells on sheet1 c10:c25 that need to go into labels 11 -26

and so on. How can i change the code above to fit those needs?


--
justchris
------------------------------------------------------------------------
justchris's Profile: http://www.excelforum.com/member.php...fo&userid=8894
View this thread: http://www.excelforum.com/showthread...hreadid=398025




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Setting up a simple loop to fill labels?


I found this bit of code... this is what i was lookin for, thanks though
Rowan.

UserForm1.Controls("Label" & i).Caption =

This Works!


--
justchris
------------------------------------------------------------------------
justchris's Profile: http://www.excelforum.com/member.php...fo&userid=8894
View this thread: http://www.excelforum.com/showthread...hreadid=398025

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
Setting Multiple Variables with a loop jlclyde Excel Discussion (Misc queries) 6 November 11th 09 09:40 PM
I need a simple loop with a 4+ row added in. pgarcia Excel Discussion (Misc queries) 5 July 19th 07 07:42 PM
TextToColumns delimiter setting ignored w/in VB loop Amy[_8_] Excel Programming 0 February 15th 05 07:15 PM
Some help w/ simple loop, please? terry b Excel Programming 6 February 6th 05 06:17 PM
simple loop macro jim27[_2_] Excel Programming 0 October 17th 04 06:36 PM


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