#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 385
Default Looping

I have this code that enter data into my worksheet from textbox and labels.
ws.Cells(iRow, 1) = iRow - 1
ws.Cells(iRow, 2) = Me.txtRFID.Value
ws.Cells(iRow, 3) = Me.DTPicker1.Value
ws.Cells(iRow, 5) = Me.TextBox1.Value
ws.Cells(iRow, 4) = Me.Label1

Problem is i could have as many as 11 textboxes and label with values never
constant. how do you write this to enter so that it enters this code the for
the tb1 and lbl1 then run again if there is tb2 and lb2 and so on. Would it
be a loop?
--
Thank you,

Jennifer
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Looping

I saw your previous posting last night. I used the result from the previous
posting to make the code below. The code below will vary the number of times
it loop based on the number of Labels it finds.

iRow = 1
For Each lbl In Controls
If Left(lbl.Name, 5) = "Label" Then
If Len(Trim(lbl.Caption)) 0 Then
labelnumber = Mid(lbl.Name, 6)

ws.Cells(iRow, 1) = iRow - 1
ws.Cells(iRow, 2) = Me.txtRFID.Value
ws.Cells(iRow, 3) = Me.DTPicker1.Value
ws.Cells(iRow, 5) = _
Me.Controls("TextBox" & labelnumber).Value
ws.Cells(iRow, 4) = lbl.Caption
iRow = iRow + 1
End If
End If
Next lbl
End Sub


"Jennifer" wrote:

I have this code that enter data into my worksheet from textbox and labels.
ws.Cells(iRow, 1) = iRow - 1
ws.Cells(iRow, 2) = Me.txtRFID.Value
ws.Cells(iRow, 3) = Me.DTPicker1.Value
ws.Cells(iRow, 5) = Me.TextBox1.Value
ws.Cells(iRow, 4) = Me.Label1

Problem is i could have as many as 11 textboxes and label with values never
constant. how do you write this to enter so that it enters this code the for
the tb1 and lbl1 then run again if there is tb2 and lb2 and so on. Would it
be a loop?
--
Thank you,

Jennifer

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 385
Default Looping

I will try it out. Thanks Joel.
--
Thank you,

Jennifer


"Joel" wrote:

I saw your previous posting last night. I used the result from the previous
posting to make the code below. The code below will vary the number of times
it loop based on the number of Labels it finds.

iRow = 1
For Each lbl In Controls
If Left(lbl.Name, 5) = "Label" Then
If Len(Trim(lbl.Caption)) 0 Then
labelnumber = Mid(lbl.Name, 6)

ws.Cells(iRow, 1) = iRow - 1
ws.Cells(iRow, 2) = Me.txtRFID.Value
ws.Cells(iRow, 3) = Me.DTPicker1.Value
ws.Cells(iRow, 5) = _
Me.Controls("TextBox" & labelnumber).Value
ws.Cells(iRow, 4) = lbl.Caption
iRow = iRow + 1
End If
End If
Next lbl
End Sub


"Jennifer" wrote:

I have this code that enter data into my worksheet from textbox and labels.
ws.Cells(iRow, 1) = iRow - 1
ws.Cells(iRow, 2) = Me.txtRFID.Value
ws.Cells(iRow, 3) = Me.DTPicker1.Value
ws.Cells(iRow, 5) = Me.TextBox1.Value
ws.Cells(iRow, 4) = Me.Label1

Problem is i could have as many as 11 textboxes and label with values never
constant. how do you write this to enter so that it enters this code the for
the tb1 and lbl1 then run again if there is tb2 and lb2 and so on. Would it
be a loop?
--
Thank you,

Jennifer

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
Looping Bob Phillips Excel Programming 0 January 11th 07 04:12 PM
looping Neal Excel Programming 2 May 19th 06 10:27 PM
Looping Steve Excel Programming 2 September 9th 05 12:45 PM
Looping Hannes Excel Programming 3 December 27th 04 09:03 PM
Looping Stuart[_9_] Excel Programming 0 October 29th 03 11:31 PM


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