Userform Textbox to Show Value of Cell and Edit Value of Cell

imav

New Member
Joined
Jun 27, 2011
Messages
21
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.

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

My userform currently shows the value of either cell A1,A2, or A3 but I also would like to be able to change the value IN the textbox and have the cell value also change.

Any ideas?:confused:
 

Excel Facts

Back into an answer in Excel
Use Data, What-If Analysis, Goal Seek to find the correct input cell value to reach a desired result
Hi Imav;

Could you make clear which cell value you want to be changed?
but I also would like to be able to change the value IN the textbox and have the cell value also change.

A1 or A2 or A3 or A1:A3 ?
 
Upvote 0
Code:
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 selext 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.

Please let me know if i can clarify anymore.

Thanks,

Mike
 
Upvote 0
I found a solution to my problem.

Code:
Dim rngText1 As Range
Dim rngText2 As Range
Private Sub Userform_Activate()
Set rngText1 = Worksheets("Sheet1").Range("A1")
Set rngText2 = Worksheets("Sheet1").Range("A2")
TextBox1.Text = rngText1.Value
TextBox2.Text = rngText2.Value
End Sub
Private Sub TextBox1_Exit(ByVal Cancel As MSForms.ReturnBoolean)
rngText1.Value = TextBox1.Text
End Sub
Private Sub TextBox2_Exit(ByVal Cancel As MSForms.ReturnBoolean)
rngText2.Value = TextBox2.Text
End Sub
:)
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,808
Members
452,944
Latest member
2558216095

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top