ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Initialize textbox values (https://www.excelbanter.com/excel-programming/302638-initialize-textbox-values.html)

phreud[_20_]

Initialize textbox values
 
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

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

Initialize textbox values
 
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)

"phreud " wrote in message
...
Hi,

I want to initialize all my textboxes when my userform is showed. They
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 if
I can set the value using the textbox name directly.

Thanks in advance

/ phreud


---
Message posted from http://www.ExcelForum.com/




phreud[_22_]

Initialize textbox values
 
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

--
Message posted from http://www.ExcelForum.com


Bob Phillips[_6_]

Initialize textbox values
 
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)

"phreud " wrote in message
...
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 to
=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?

/ phreud


---
Message posted from http://www.ExcelForum.com/




phreud[_24_]

Initialize textbox values
 
Bob Phillips wrote:
[b]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

--
Message posted from http://www.ExcelForum.com



All times are GMT +1. The time now is 12:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com