PDA

View Full Version : Referring to lots of Text Boxes on a userform



GreenTree
06-27-2007, 12:42 PM
Let's say I have a user form with ten text boxes on it. I'd like to be able to specify which one I put a value in with a variable, so that if N = 1, I'm dealing with .textbox1.value, if N=2 then .textbox2.value, etc. Is there an easy way to do that? (Perfectly happy to name the boxes whatever they'd need to make such a scheme work.)

Followup question, suppose I have the textboxes in rows and columns in the user form; can I name them in such a way that when R = 12 and C = 2 I'm dealing with with .textboxR12C2.value? (If not, I can do something equivalent with a solution to the first question above, but if this is easy, why do an unnecessary workaround?)

Thanks!

G.T.

Simon Lloyd
06-27-2007, 12:59 PM
Something like:

Dim N as Integer
N= Range("B1").Value
Userform1.Textbox & N.Value = Range("A1").Value
not tested but if you had the value of 10 in Range B1 then you are dealing with TextBox10 and the value of that textbox would be that of A1, does this help?

mvidas
06-27-2007, 01:27 PM
Hi,

You can refer to it by name using the Controls collection:UserForm1.Controls("TextBox" & N).Value
EDIT: Missed the followup question

Followup question, suppose I have the textboxes in rows and columns in the user form; can I name them in such a way that when R = 12 and C = 2 I'm dealing with with .textboxR12C2.value?Sure, you can name them whatever you want, as long as it starts with a letter, has no spaces, and doesnt use any invalid characters.

GreenTree
06-27-2007, 03:40 PM
Many thanks -- that's exactly what I needed!

Solved -- this forum is fantastic!

:yes

Green Tree