ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Save value on form (https://www.excelbanter.com/excel-programming/334291-save-value-form.html)

scantor145[_14_]

Save value on form
 

Excel 2003 w/Visual Basic 6.3

At a point in my macro I calculate a value, and then assign that valu
to a text box on another form. My questions a

1) Can that value be saved on the form so that the next time I run th
macro the value in the text box is already stored?

2) Can the value in the text box be formatted, e.g. to display only
decimal places

Thank

--
scantor14
-----------------------------------------------------------------------
scantor145's Profile: http://www.excelforum.com/member.php...fo&userid=1476
View this thread: http://www.excelforum.com/showthread.php?threadid=38647


Jim Thomlinson[_4_]

Save value on form
 
You need to store the value from the txtbox on a sheet somewhere. The sheet
can be hidden from the user. You can then use code similar to this to
retrieve the value...

Private Sub UserForm_Initialize()
TextBox1.Text = Format(Sheet1.Range("A1").Value, "#,##0.00")
End Sub

Where you have stored the text box value in sheet1 cell A1
--
HTH...

Jim Thomlinson


"scantor145" wrote:


Excel 2003 w/Visual Basic 6.3

At a point in my macro I calculate a value, and then assign that value
to a text box on another form. My questions a

1) Can that value be saved on the form so that the next time I run the
macro the value in the text box is already stored?

2) Can the value in the text box be formatted, e.g. to display only 2
decimal places

Thanks


--
scantor145
------------------------------------------------------------------------
scantor145's Profile: http://www.excelforum.com/member.php...o&userid=14766
View this thread: http://www.excelforum.com/showthread...hreadid=386473



speyry

Save value on form
 

1) The easiest way I know how is to write the value to a cell. Then whe
the userform opens again, set the "controlsource" of the textBox to th
value in the cell that you previously stored the value in.

RANGE(\"A1\").VALUE = TEXTBOX1.VALU
'After closed and reopened

*TextBox1.Value = Range("A1") *
'OR
*TextBox1.ControlSource = Range("A1")*

With this method, if changes are made to the value, it can creat
problems sometimes

Or something similar depending on how your user form is set u

--
speyr
-----------------------------------------------------------------------
speyry's Profile: http://www.excelforum.com/member.php...fo&userid=2512
View this thread: http://www.excelforum.com/showthread.php?threadid=38647


Fausto Arinos Barbuto

Save value on form
 

"scantor145"

Excel 2003 w/Visual Basic 6.3


At a point in my macro I calculate a value, and then assign that value
to a text box on another form. My questions a


1) Can that value be saved on the form so that the next time I run the
macro the value in the text box is already stored?


2) Can the value in the text box be formatted, e.g. to display only 2
decimal places


Well, at least in Excel you can use Round(). For example:

TextBox1.Text = Round(variable,4)

"variable" will then be displayed as 4-decimal place figure in TextBox1.
You might also embellish the display, for example:

TextBox1.Text = "Execution time: " & Round(variable,4) & " seconds."

---Fausto




STEVE BELL

Save value on form
 
In your code your might insert a Name and set it = to the value.
Than refer to the name to set the textbox.

recorded code in Excel 2000
ActiveWorkbook.Names.Add Name:="Myvalue", RefersToR1C1:="=13"


--
steveB

Remove "AYN" from email to respond
"speyry" wrote in
message ...

1) The easiest way I know how is to write the value to a cell. Then when
the userform opens again, set the "controlsource" of the textBox to the
value in the cell that you previously stored the value in.

RANGE(\"A1\").VALUE = TEXTBOX1.VALUE
'After closed and reopened

*TextBox1.Value = Range("A1") *
'OR
*TextBox1.ControlSource = Range("A1")*

With this method, if changes are made to the value, it can create
problems sometimes

Or something similar depending on how your user form is set up


--
speyry
------------------------------------------------------------------------
speyry's Profile:
http://www.excelforum.com/member.php...o&userid=25128
View this thread: http://www.excelforum.com/showthread...hreadid=386473





All times are GMT +1. The time now is 08:33 AM.

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