I am trying to get a text box to show a specific cell's value when the form is opened. I know there has to be a property that I can change to do this, but which one? Or, if not, how do I do it?
TextBox Text
Collapse
X
-
What are you working with? VBA built into Excel? Which version?Originally posted by if1467I am trying to get a text box to show a specific cell's value when the form is opened. I know there has to be a property that I can change to do this, but which one? Or, if not, how do I do it?
The textbox's .Text property is most likely what you want to change.
As for where to place the code, I'd guess the form's Activate, Layout or Initialize event procedure. -
Yeap, its not a propertry, is an event, its the initializa event of the form, and should say something like:Originally posted by if1467I am trying to get a text box to show a specific cell's value when the form is opened. I know there has to be a property that I can change to do this, but which one? Or, if not, how do I do it?
[CODE=vb]Textbox1.text= worksheets("she et1").cells(5,1 ).value 'This is for cell A5[/CODE]
HTHComment
-
I am very new to using forms, so I am going to need some more help.Originally posted by kadgharYeap, its not a propertry, is an event, its the initializa event of the form, and should say something like:
[CODE=vb]Textbox1.text= worksheets("she et1").cells(5,1 ).value 'This is for cell A5[/CODE]
HTH
Right now I have a form with 3 options. The "OK" command code is:
The form that I need a textbox filled is on the "Coupon" form.Code:Private Sub CommandButton1_Click() Unload Me If ListBox1.ListIndex = -1 Then MsgBox "No item selected", vbExclamation Exit Sub End If Range("G4") = ListBox1.ListIndex + 1 If Range("G4") = "1" Then Purchase_Action.Show End If If Range("G4") = "2" Then Sale_Action.Show End If If Range("G4") = "3" Then Coupon.Show End If Unload Me End Sub
I am not sure what is meant by the inititialize event, and where to place the code for the text.Comment
-
To find the event procedures, double-click on the userform in the editor. This should bring up the code window for the userform. You can use the two pulldown listboxes at the top of the window to select the form or a control, and the various events that pertain to them.Comment
-
Thanks a bunch!! Now how do I get the textbox to be formated the same as the referenced cell?Originally posted by Killer42To find the event procedures, double-click on the userform in the editor. This should bring up the code window for the userform. You can use the two pulldown listboxes at the top of the window to select the form or a control, and the various events that pertain to them.Comment
-
[CODE=vb]TextBox1.Font.N ame = Cells(1, 1).Font.NameOriginally posted by if1467Thanks a bunch!! Now how do I get the textbox to be formated the same as the referenced cell?
TextBox1.Font.S ize = Cells(1, 1).Font.Size[/CODE]
or
[CODE=vb]TextBox1.Font.N ame = Range("A4").Fon t.Name
TextBox1.Font.S ize = Range("A4").Fon t.Size[/CODE]
and the same for each font's property you want to copyComment
-
I guess I should have been morespecific if I wanted a more specific answer. The text that I am putting in the textbox is supposed to be a percentage like 10.25%, but the box is showing 0.1025. How do I format the text for this criteria?Originally posted by kadghar[CODE=vb]TextBox1.Font.N ame = Cells(1, 1).Font.Name
TextBox1.Font.S ize = Cells(1, 1).Font.Size[/CODE]
or
[CODE=vb]TextBox1.Font.N ame = Range("A4").Fon t.Name
TextBox1.Font.S ize = Range("A4").Fon t.Size[/CODE]
and the same for each font's property you want to copyComment
-
That might be a little bit more complex, since the cells have the NumberFormat property, that textboxes dont have... but assuming the Format function have the same parameters as the Excel's property, something like this should do:Originally posted by if1467I guess I should have been morespecific if I wanted a more specific answer. The text that I am putting in the textbox is supposed to be a percentage like 10.25%, but the box is showing 0.1025. How do I format the text for this criteria?
[CODE=vb]TextBox1.Text = Format(TextBox1 .Text, Range("A2").Num berFormat)[/CODE]
If that doesn't work, i think we'll have to make a HomeMade function for this purpose.Comment
-
Thanks for the tip.Originally posted by kadgharThat might be a little bit more complex, since the cells have the NumberFormat property, that textboxes dont have... but assuming the Format function have the same parameters as the Excel's property, something like this should do:
[CODE=vb]TextBox1.Text = Format(TextBox1 .Text, Range("A2").Num berFormat)[/CODE]
If that doesn't work, i think we'll have to make a HomeMade function for this purpose.
I tried
[CODE=vb]TextBox1.Text = Format(TextBox1 .Text, Range("A2").Num berFormat)[/CODE]
and it returned "Ge1eral"
so I tried
[CODE=vb]TextBox1.Text = Format(TextBox1 .Text, Worksheets("Rev iewer Back-Up").Cells(2, 6).NumberFormat )[/CODE]
and it worked!!Comment
Comment