ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Looping (https://www.excelbanter.com/excel-programming/402045-looping.html)

Jennifer

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

joel

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


Jennifer

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



All times are GMT +1. The time now is 03:42 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com