Initialize textbox values

P

phreud

Hi,

I want to initialize all my textboxes when my userform is showed. The
are all connected to the worksheet with controlsource.

I tried using 'Me.txtSomebox.Value = 14' i the Userform_Initialize(
event, but it doesn't change the value. If I write to the cell (range
in the worksheet directly, it works. Why is this? It's alot clearer i
I can set the value using the textbox name directly.

Thanks in advance

/ phreu
 
B

Bob Phillips

Because you are tied to a worksheet, that is where it is getting the values
from.

Why not just change the worksheet cells directly, rather than the
textbox(es)?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
P

phreud

Since I got no answers, I'll try to clarify:

In my worksheet, I have in Cell A2 the value 10.

In my UserForm I have a textbox (TextBox1) with ControlSource set t
=A2

In UserForm_Initialize() I try to set: 'Me.TextBox1.Value = 14'.

This does not change the value. It's still 10 when I run the code.

If I however use this line
'Thisworkbook.Worksheets(1).Range("A2").Value = 14'

it works fine. Can someone please explain why?

/ phreu
 
B

Bob Phillips

I replied, and this was what I wrote

Because you are tied to a worksheet, that is where it is getting the values
from.

Why not just change the worksheet cells directly, rather than the
textbox(es)?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)
 
P

phreud

Bob said:
Because you are tied to a worksheet, that is where it is gettin
the values
from.

Why not just change the worksheet cells directly, rather than the
textbox(es)?

That's what I had to do. I just thought it should work the other wa
too. It's a whole lot clearer to type:

txtInitialCost.Value = 44

than:

Thisworkbook.Range("B45").Value = 44

I was initializing up towards 50 values, so it would have been alo
easier
 
Top