+ Reply to Thread
Results 1 to 7 of 7

Thread: Userform TextBox that Shows cell Value but can also be Edited

  1. #1
    Registered User
    Join Date
    07-13-2011
    Location
    North Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Question Userform TextBox that Shows cell Value but can also be Edited

    Hey all,

    I am trying to figure out how I can make a textbox that will show the value of a cell but also allow you to change the value of that cell by changing the text in the TextBox.

    Here is what I have so far.


    Private Sub UserForm_Activate()
        'Australia
            If ComboBox1 = "Australia" Then
                TextBox1.Text = Worksheets("Sheet1").Range("A1")
            End If
        'China
            If ComboBox1 = "China" Then
                TextBox1.Text = Worksheets("Sheet1").Range("A2")
            End If
        'India
            If ComboBox1 = "India" Then
                TextBox1.Text = Worksheets("Sheet1").Range("A3")
            End If
    End Sub
    Right now when you select Australia in the ComboBox it will put the A1 Value in the TextBox.

    Likewise when you select China the textbox displays A2, and India shows A3.

    For example I want to select Australia in the ComboBox, Have the TextBox display the cellvalue for A1, and allow me to change the text that appears in the textbox to change the value of the cell it is currently showing. in this example A1.

    Example. I select China in the ComboBox, the Textbox shows the Value of Cell A2, and I can change the text in the textbox to change the value of cell A2.

    Any ideas?

    Please let me know if i can clarify anymore.

    Thanks,

    Mike
    Last edited by imav; 07-19-2011 at 08:35 AM.

  2. #2
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Userform TextBox that Shows cell Value but can also be Edited

    If you use something like:
    Dim rngText1 as Range
    Private Sub UserForm_Activate()
        'Australia
            If ComboBox1 = "Australia" Then
                set rngText1  = Worksheets("Sheet1").Range("A1")
            End If
        'China
            If ComboBox1 = "China" Then
                set rngText1  = Worksheets("Sheet1").Range("A2")
            End If
        'India
            If ComboBox1 = "India" Then
                set rngText1  = Worksheets("Sheet1").Range("A3")
            End If
           Textbox1.Text = set rngText1.Value
    End Sub
    then in the exit event of the textbox you can use:
    rngText1.Value  = Textbox1.text

  3. #3
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Userform TextBox that Shows cell Value but can also be Edited

    If you use something like:
    Dim rngText1 as Range
    Private Sub UserForm_Activate()
        'Australia
            If ComboBox1 = "Australia" Then
                set rngText1  = Worksheets("Sheet1").Range("A1")
            End If
        'China
            If ComboBox1 = "China" Then
                set rngText1  = Worksheets("Sheet1").Range("A2")
            End If
        'India
            If ComboBox1 = "India" Then
                set rngText1  = Worksheets("Sheet1").Range("A3")
            End If
           Textbox1.Text = set rngText1.Value
    End Sub
    then in the exit event of the textbox you can use:
    rngText1.Value  = Textbox1.text

  4. #4
    Forum Guru snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,151

    Re: Userform TextBox that Shows cell Value but can also be Edited

    Probably this suffices:

    Private Sub UserForm_Activate()
      TextBox1.Text = Worksheets("Sheet1").cells(combobox1.listindex+1,1)
    End Sub



  5. #5
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    Apparently I can't say
    MS-Off Ver
    Apparently I can't say
    Posts
    8,274

    Re: Userform TextBox that Shows cell Value but can also be Edited

    Doesn't really address the question though, does it?

  6. #6
    Registered User
    Join Date
    07-13-2011
    Location
    North Carolina, USA
    MS-Off Ver
    Excel 2007
    Posts
    11

    Re: Userform TextBox that Shows cell Value but can also be Edited

    Romperstomper your solution works perfectly I really appreciate it.

  7. #7
    Forum Guru, retired Admin royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    25,640

    Re: Userform TextBox that Shows cell Value but can also be Edited

    Something like this

    Private Sub ComboBox1_Change()
    Me.TextBox1.Value = Cells(Me.ComboBox1.ListIndex + 1, 1).Value
    End Sub
    
    
    Private Sub TextBox1_AfterUpdate()
    Cells(Me.ComboBox1.ListIndex + 1, 1).Value = Me.TextBox1.Value
    
    End Sub
    Hope that helps.

    RoyUK
    --------
    If you are pleased with a member's answer then use the Star icon to rate it, if you are pleased enough to part with cash consider a donation to Children in Need

    For Excel Tips & Solutions, free examples and tutorials why not check out my downloads

    New members please read & follow the Forum Rules

    Remember to mark your questions Solved and rate the answer(s)

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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

Search Engine Friendly URLs by vBSEO 3.2.0