473,385 Members | 1,309 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

TextBox Text

25
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?
Feb 28 '08 #1
9 1770
Killer42
8,435 Expert 8TB
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?
What are you working with? VBA built into Excel? Which version?

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.
Feb 28 '08 #2
kadghar
1,295 Expert 1GB
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?
Yeap, its not a propertry, is an event, its the initializa event of the form, and should say something like:

Expand|Select|Wrap|Line Numbers
  1. Textbox1.text= worksheets("sheet1").cells(5,1).value  'This is for cell A5
HTH
Feb 28 '08 #3
if1467
25
Yeap, its not a propertry, is an event, its the initializa event of the form, and should say something like:

Expand|Select|Wrap|Line Numbers
  1. Textbox1.text= worksheets("sheet1").cells(5,1).value  'This is for cell A5
HTH
I am very new to using forms, so I am going to need some more help.

Right now I have a form with 3 options. The "OK" command code is:

Expand|Select|Wrap|Line Numbers
  1. Private Sub CommandButton1_Click()
  2. Unload Me
  3. If ListBox1.ListIndex = -1 Then
  4.     MsgBox "No item selected", vbExclamation
  5.     Exit Sub
  6. End If
  7. Range("G4") = ListBox1.ListIndex + 1
  8. If Range("G4") = "1" Then
  9. Purchase_Action.Show
  10. End If
  11. If Range("G4") = "2" Then
  12. Sale_Action.Show
  13. End If
  14. If Range("G4") = "3" Then
  15. Coupon.Show
  16. End If
  17. Unload Me
  18. End Sub
The form that I need a textbox filled is on the "Coupon" form.

I am not sure what is meant by the inititialize event, and where to place the code for the text.
Feb 28 '08 #4
Killer42
8,435 Expert 8TB
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.
Feb 29 '08 #5
if1467
25
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.
Thanks a bunch!! Now how do I get the textbox to be formated the same as the referenced cell?
Feb 29 '08 #6
kadghar
1,295 Expert 1GB
Thanks a bunch!! Now how do I get the textbox to be formated the same as the referenced cell?
Expand|Select|Wrap|Line Numbers
  1. TextBox1.Font.Name = Cells(1, 1).Font.Name
  2. TextBox1.Font.Size = Cells(1, 1).Font.Size
or

Expand|Select|Wrap|Line Numbers
  1. TextBox1.Font.Name = Range("A4").Font.Name
  2. TextBox1.Font.Size = Range("A4").Font.Size
and the same for each font's property you want to copy
Feb 29 '08 #7
if1467
25
Expand|Select|Wrap|Line Numbers
  1. TextBox1.Font.Name = Cells(1, 1).Font.Name
  2. TextBox1.Font.Size = Cells(1, 1).Font.Size
or

Expand|Select|Wrap|Line Numbers
  1. TextBox1.Font.Name = Range("A4").Font.Name
  2. TextBox1.Font.Size = Range("A4").Font.Size
and the same for each font's property you want to copy
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?
Feb 29 '08 #8
kadghar
1,295 Expert 1GB
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?
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:

Expand|Select|Wrap|Line Numbers
  1. TextBox1.Text = Format(TextBox1.Text, Range("A2").NumberFormat)
If that doesn't work, i think we'll have to make a HomeMade function for this purpose.
Feb 29 '08 #9
if1467
25
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:

Expand|Select|Wrap|Line Numbers
  1. TextBox1.Text = Format(TextBox1.Text, Range("A2").NumberFormat)
If that doesn't work, i think we'll have to make a HomeMade function for this purpose.
Thanks for the tip.

I tried

Expand|Select|Wrap|Line Numbers
  1. TextBox1.Text = Format(TextBox1.Text, Range("A2").NumberFormat)
and it returned "Ge1eral"
so I tried

Expand|Select|Wrap|Line Numbers
  1. TextBox1.Text = Format(TextBox1.Text, Worksheets("Reviewer Back-Up").Cells(2, 6).NumberFormat)
and it worked!!
Mar 3 '08 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Rodrigo DeJuana | last post by:
Howdy, I'm new to this .net stuff and really have little to no training. Im trying to create a new page for a web form, so i have been pretty much jsut coping code. I having some issue with...
0
by: Newasps | last post by:
Hi guys, I have a problem with UpdateCommand Event. In tihs event Ä°'m creating required controls to get that controls' values and also get them. But when I try to get updated values I'm getting the...
7
by: I am Sam | last post by:
I have a DataGrid that is passing information to a stored procedure properly but the parameters aren't being casted properly. I was woundering if anyone can tell me how I should properly cast the...
11
by: Keith | last post by:
I apologize for those of you who think I'm posting on the same topic. It is not that I don't appreciate all of your comments - and I'm definitely reading them all - but I think I have a differing...
6
by: Steve | last post by:
I am new to vb.net. I have a textbox. I want the user to be able to only enter numbers between 2 and 12 into the textbox. Is there a way to do this? Thanks for any help.
3
by: DotNetNewbie | last post by:
I am reading the book Teach Yourself Microsoft Visual Basic .Net 2003 in 21 Days. I am having trouble getting one of the exercises to work at the end of day 4. Exercises: 1. Create a new...
3
by: Brad Rogers | last post by:
All, Being immersed in vb.net and trying CSharp after almost a year I forgot the differences. I like vb fixing the uppercase/lowercase names and seeming to be more flexible to code entry. ...
8
by: Filipe Marcelino | last post by:
Hi, I'm trying to create a textbox inheriting from the standard textbox. I would like to: 1. repaint the textbox border; 2. define a color for that border; Till now I made this:
0
by: Jacob Donajkowski | last post by:
Once the user logs in I want to have the users switch from the Roster View to the Profile View and enter their profile infomation and save it. Then the next time they login and go to the Profile...
1
by: Andy B | last post by:
I have this code: protected void EditEventsWizard_NextButtonClick(object sender, WizardNavigationEventArgs e) { //get the values from the DetailsView TextBox StartTime =...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.