Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 249
Default using For statement for populting textbox references

I use the following type of code to populate textboxes in userforms

Me.txt1.Value = ws.Range("A10").Value
Me.txt2.Value = ws.Range("A11").Value
Me.txt3.Value = ws.Range("A12").Value
Me.txt4.Value = ws.Range("A13").Value
Me.txt5.Value = ws.Range("A14").Value
Me.txt6.Value = ws.Range("A15").Value
Me.txt7.Value = ws.Range("A16").Value
Me.txt8.Value = ws.Range("A17").Value
etc etc...

Is there a way to use a "For i = 1 to 8" statement which will do the above
code : for example

Dim i as Integer
For i = 1 to 8
Me.txt & i.Value = ws.Range("A" & Cstr(i + 9))
Next i

Can anyone help with the syntax for this?

Many thanks,

Roger
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default using For statement for populting textbox references

You can do it like this...

For X = 1 To 8
Me.Controls("txt" & X).Value = ws.Cells(9 + X, "D").Value
Next

If you Dim your variables (and you should), X would be a Long.

--
Rick (MVP - Excel)


"Roger on Excel" wrote in message
...
I use the following type of code to populate textboxes in userforms

Me.txt1.Value = ws.Range("A10").Value
Me.txt2.Value = ws.Range("A11").Value
Me.txt3.Value = ws.Range("A12").Value
Me.txt4.Value = ws.Range("A13").Value
Me.txt5.Value = ws.Range("A14").Value
Me.txt6.Value = ws.Range("A15").Value
Me.txt7.Value = ws.Range("A16").Value
Me.txt8.Value = ws.Range("A17").Value
etc etc...

Is there a way to use a "For i = 1 to 8" statement which will do the above
code : for example

Dim i as Integer
For i = 1 to 8
Me.txt & i.Value = ws.Range("A" & Cstr(i + 9))
Next i

Can anyone help with the syntax for this?

Many thanks,

Roger


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
What references do I need to program a Textbox and an Image? Jose Manuel Excel Programming 3 September 16th 09 02:34 AM
How remove invalid references in ToolsReferences drop down box? [email protected] Excel Programming 1 July 7th 09 09:52 AM
Help with converting a block of cells with Absolute and mixed references to relative references Vulcan Excel Worksheet Functions 3 December 13th 07 11:43 PM
Excel VBA putting text from textbox into SQL statement [email protected] Excel Programming 4 October 20th 06 02:40 PM
How to rename references from range names to cell references Abbas Excel Discussion (Misc queries) 1 May 24th 06 06:18 PM


All times are GMT +1. The time now is 04:27 PM.

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"