Autopopulate TextBox1

  • Thread starter Todd Huttenstine
  • Start date
T

Todd Huttenstine

Hey. I have a number value in cell N1. I have a VBA textbox1 on userform1.
I want textbox1 to automatically populate with cell N1 value. How do I do
this?


Thank you.

Todd Huttenstine
 
D

Dave Peterson

Something like:

Option Explicit
Private Sub UserForm_Initialize()
Me.TextBox1.Value = Worksheets("sheet1").Range("n1").Value
'or if you have to format it:
Me.TextBox1.Value _
= Format(Worksheets("sheet1").Range("N1").Value, "mm/dd/yyyy")
End Sub
 
T

Todd Huttenstine

hey thank you. Can you tell me what the significance of the Me. is for?
 
D

Dave Peterson

It refers to the thing that holds the next object/property. In this case, since
the code is under a userform, it refers to that userform.

If you had code behind a worksheet (like worksheet_change), you could refer to
objects that are held on that sheet. (Me.range("a1") would be the same as
worksheets("sheet1").range("a1") if the code was under Sheet1.)

I use it because I'm lazy. When I type the dot after me, I get the intellisense
to help me complete my code.

Instead of having to type:
textbox1.value =
I typed:
me.te
and hit tab.
and got
me.textbox1
I typed .v
and hit tab and got:
me.TextBox1.Value
(if there are lots that start with the same set of letters, you can pick from
the list.)

Saves wear and tear on searching for typos.
 
T

Todd Huttenstine

because when I bring the userform up, it looks in that cell (cell N1) to
find what the next order number is. Cell N1 contains a formula and I dont
want to overwrite that formula because it is used for the next order. N1 is
always looking one ahead. I may be wrong but I thought if I linked it, then
whatever I typed would overwrite the cell N1. Having the textbox
autopopulate with the value of N1 is just a time saver.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top