Save value on form

S

scantor145

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 are:

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
 
G

Guest

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
 
S

speyry

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
 
F

Fausto Arinos Barbuto

scantor145 said:
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 are:
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
 
S

STEVE BELL

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"
 

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