LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 80
Default Forms - Loop thru text boxes

Hi All,

I have a userform with some 100 text boxes on it.

On initialization l apply the values to the text boxes using this code
(extract only)

Private Sub UserForm_Initialize()

Sheets("List_CellsLids").Select
Range("N2").Select

With frmAccom

tbUnit1.Text = ActiveCell.Value
tbUnit2.Text = ActiveCell.Offset(1, 0).Value
tbUnit3.Text = ActiveCell.Offset(2, 0).Value
tbUnit4.Text = ActiveCell.Offset(3, 0).Value
tbUnit5.Text = ActiveCell.Offset(4, 0).Value
tbUnit6.Text = ActiveCell.Offset(5, 0).Value
tbUnit7.Text = ActiveCell.Offset(6, 0).Value
tbUnit8.Text = ActiveCell.Offset(7, 0).Value
tbUnit9.Text = ActiveCell.Offset(8, 0).Value
tbUnit10.Text = ActiveCell.Offset(9, 0).Value
End With
End Sub

On 'Enter' l would normally enter the following code (extract only) so that
if the user 'edits' a value it is written to the appropriate cells

ActiveCell.Value = tbUnit1.Text
ActiveCell.Offset(1, 0).Value = tbUnit2.Text
ActiveCell.Offset(2, 0).Value = tbUnit3.Text
ActiveCell.Offset(3, 0).Value = tbUnit4.Text
ActiveCell.Offset(4, 0).Value = tbUnit5.Text
ActiveCell.Offset(5, 0).Value = tbUnit6.Text
ActiveCell.Offset(6, 0).Value = tbUnit7.Text
ActiveCell.Offset(7, 0).Value = tbUnit8.Text
ActiveCell.Offset(8, 0).Value = tbUnit9.Text
ActiveCell.Offset(9, 0).Value = tbUnit10.Text

However because l have to do this for so many text boxes and l have several
more to write l was hoping to apply the values using a vba / loop code
something like the following

Dim tbni As Integer

Private Sub cmdEnter_Click()
'Sheets("List_CellsLids").Select
'Range("N2").Select
tbni = 1
For i = 1 To 10
ActiveCell.Value = "tbUnit" & tbni & ".Value"
ActiveCell.Offset(1, 0).Activate
tbni = tbni + 1
Next

I think the answer is somewhere in the syntax. Can anybody help please?

Regards

Michael Beckinsale


 
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
User Form Text Boxes - Copy format of text boxes NDBC Excel Discussion (Misc queries) 3 July 2nd 09 02:02 AM
Boxes in Forms PaulW Excel Discussion (Misc queries) 0 March 10th 06 03:18 PM
forms / text boxes JT Excel Programming 1 January 23rd 06 08:07 PM
Setting Property Values of Text Boxes within Forms SkyEyes Excel Programming 1 July 1st 05 07:06 PM
Loop through Labels and Text Boxes within module code Dan Gardner Excel Programming 2 December 22nd 04 11:29 PM


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