Loading
Ozgrid Excel Help & Best Practices Forums

Excel Video Tutorials / Excel Dashboards Reports



Results 1 to 4 of 4

Thread: Pass Cell Value To UserForm TextBox As Text

  1. #1
    Join Date
    3rd April 2008
    Posts
    11

    Pass Cell Value To UserForm TextBox As Text

    Hi,
    I am new to this forum and not really sure how this question will be routed.

    I am trying to learn how to write a macro and create a UserForm. While doing so, I ran into a problem trying to capture an existing data in a cell ("C5") from a sheet called details. I just wanted to display the content of cell "C5" into the textbox that I created in my UserForm.

    I appreciate any help and thanks to the technology like this.

    Thanks and Regards,

    Excel Video Tutorials / Excel Dashboards Reports


  2. #2
    Join Date
    23rd April 2007
    Posts
    3,481

    Re: Capture Data From Sheet To Show In Userform

    There are two techniques that you can use.
    Putting this in a normal module
    VB:
    UserForm1.TextBox1.Text = CStr(Range("c5").Value) 
    UserForm1.Show 
    
    
    Will put C5's contents into the textbox before the userform is shown. Replacing CStr(Range("c5").Value) with a variable gives you control over which value goes into the text box.


    If you know that C5's value will always be the intial value of the text box, this code can be put in the UserForm's code module. The range is fully qualified to insure that which sheet is active doesn't affect the right value being put in the text box. This consideration also applies to the other technique, but since the range reference is outside of the userform, its less of a suprise.
    VB:
    Private Sub UserForm_Initialize() 
        Me.TextBox1.Text = CStr(ThisWorkbook.Sheets("Sheet1").Range("C5").Value) 
    End Sub 
    
    
    In both cases
    VB:
    UnLoad Userform1 
    
    
    will erase the contents of the text box. The textboxe's value must be put in a cell or variable before that line is executed

    Excel Video Tutorials / Excel Dashboards Reports


  3. #3
    Join Date
    3rd April 2008
    Posts
    11

    Re: Capture Data From Sheet To Show In Userform

    It works, thank you very much.

    Excel Video Tutorials / Excel Dashboards Reports


  4. #4
    Join Date
    23rd April 2007
    Posts
    3,481

    Re: Capture Data From Sheet To Show In Userform

    Glad to have helped.

    Excel Video Tutorials / Excel Dashboards Reports


Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Possible Answers

  1. Replies: 4
    Last Post: June 27th, 2008, 12:29
  2. Replies: 5
    Last Post: May 16th, 2008, 11:02
  3. Enter UserForm TextBox Text Into Cell
    By EricJ in forum EXCEL HELP
    Replies: 3
    Last Post: March 19th, 2008, 07:58
  4. Replies: 2
    Last Post: January 7th, 2008, 16:43
  5. Replies: 6
    Last Post: August 24th, 2007, 12:45

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
porno