combobox selects cell and text box info updates corisponding cell

VBAer

New Member
Joined
Jun 13, 2017
Messages
10
Hello,
im not sure how to code this (obviously lol).

i have a simple user form that has 1 combox that lists all items in column a. I have a text box that lists the text in column next to it (column b). what im not sure how to do is to let the user type in a new item into the combobox and text box and add it to the list or to have the user change the info in the text box and have it update in the corisponding excel sheet. below is the code I have for selecting the column and text box.

just don't know what to write to let them change the info in the cells.

I also have set up that the value in the combobox is stored in cell gg1 but im not sure if its just the face value or the actual row/column location value.


Private Sub UserForm_Initialize()
Dim i As Long
Dim LastRow As Long
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
LastRow = ws.range("A" & Rows.Count).End(xlUp).Row
For i = 4 To LastRow
Me.ComboBox1.AddItem ws.Cells(i, "A").Value
Next i
Application.WindowState = xlMinimized
End Sub
Private Sub ComboBox1_Change()
Dim i As Long
Dim LastRow As Long
Dim ws As Worksheet
Set ws = Sheets("Sheet1")
LastRow = ws.range("A" & Rows.Count).End(xlUp).Row
For i = 4 To LastRow
If (Me.ComboBox1.Value) = ws.Cells(i, "A") Then
Me.TextBox1 = ws.Cells(i, "B").Value
End If
ws.range("gg1").Value = Me.ComboBox1.Value = x
Next i
End Sub
Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
Application.WindowState = xlNormal
End Sub


any help is greatly appreciated.
 

Excel Facts

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
I also know that I will mostlikly have to add buttons update and remove for the code to be in those.
 
Upvote 0
So you want to load all the value in Column A into Combobox1.
And you want to load all the values in column "B" into a textbox

You said:
I have a text box that lists the text in column next to it (column b)

Is that correct?
 
Upvote 0
Please explain in more detail what your wanting to do.

And give me the names of all you controls.
 
Upvote 0
I think I now see what you want.

If you want to add items to the Combobox it would be best to enter the value you want into Textbox1.
Then Double click on Textbox1 and the value will be added to the Combobox
 
Upvote 0
You can load your Combobox with values like this if you want.

Code:
Private Sub UserForm_Initialize()
Dim Lastrow As Long
Lastrow = Cells(Rows.Count, "A").End(xlUp).Row
ComboBox1.List = Range("A1:A" & Lastrow).Value
End Sub
 
Upvote 0

Forum statistics

Threads
1,223,249
Messages
6,171,031
Members
452,374
Latest member
keccles

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