Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
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
Posted to microsoft.public.excel.programming
|
|||
|
|||
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 |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
What references do I need to program a Textbox and an Image? | Excel Programming | |||
How remove invalid references in ToolsReferences drop down box? | Excel Programming | |||
Help with converting a block of cells with Absolute and mixed references to relative references | Excel Worksheet Functions | |||
Excel VBA putting text from textbox into SQL statement | Excel Programming | |||
How to rename references from range names to cell references | Excel Discussion (Misc queries) |