TextBox Value based off ComboBox value

thechad

Board Regular
Joined
Apr 28, 2014
Messages
118
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
Greetings all,

I have been poking around for a while and I'm not able to find what I'm looking for.

I am trying to populate textboxes based off a user selected option through a combobox from the same column.

For example...if a user selects 258954Z from the combobox (column 1 on worksheet "Sheet1"), I need the textboxes to show corresponding values from the same row from columns 2, 3, 4, etc. Seems like a fairly simple solution but I just can't get anything to work.

Further to my ask above, I would also like a command button that once clicked, the data that is populated based on the combobox will be copy and pasted into "Sheet2" on the last row without text.

Any help as always is greatly appreciated.

Thanks,
Chad
 

Excel Facts

How to total the visible cells?
From the first blank cell below a filtered data set, press Alt+=. Instead of SUM, you will get SUBTOTAL(9,)
Hi @thechad . Thanks for posting on the forum.

You don't mention what the textboxes are called or which column goes in which textbox.
But I hope you won't have trouble adapting them in the following code

For when you change the value in the ComboBox:
VBA Code:
Private Sub ComboBox1_Change()
  Dim f As Range
 
  If ComboBox1.ListIndex = -1 Or ComboBox1.Value = "" Then
    Exit Sub
  End If

  With Sheets("Sheet1")
    'column 1 (A) on worksheet "Sheet1"
    Set f = .Range("A:A").Find(ComboBox1.Value, , xlValues, xlWhole, , , False)
    If Not f Is Nothing Then
      'I need the textboxes to show corresponding values from the same row from columns 2, 3, 4, etc.
      TextBox1.Value = .Range("B" & f.Row).Value
      TextBox2.Value = .Range("C" & f.Row).Value
      TextBox3.Value = .Range("D" & f.Row).Value
      TextBox4.Value = .Range("E" & f.Row).Value
      TextBox5.Value = .Range("F" & f.Row).Value
    End If
  End With
End Sub


I would also like a command button
VBA Code:
Private Sub CommandButton1_Click()
  Dim f As Range
  Dim lr As Long
 
  If ComboBox1.ListIndex = -1 Or ComboBox1.Value = "" Then
    Exit Sub
  End If

  With Sheets("Sheet2")
    'copy and pasted into "Sheet2" on the last row without text.
    lr = .Range("A" & Rows.Count).End(3).Row + 1
    .Range("A" & lr).Value = ComboBox1.Value
    .Range("B" & lr).Value = TextBox1.Value
    .Range("C" & lr).Value = TextBox2.Value
    .Range("D" & lr).Value = TextBox3.Value
    .Range("E" & lr).Value = TextBox4.Value
    .Range("F" & lr).Value = TextBox5.Value
  End With
End Sub
--------------
Let me know the result and I'll get back to you as soon as I can.
Sincerely
Dante Amor
--------------
 
Upvote 0
Solution
Dante...these both work absolutely amazing! Thank you so much for your help. But...

After implementing your code, and using it a bit, I would like to go a different route with some of the functionality and could definitely use your help. Instead of using a ComboBox I would like to use a TextBox (named PON) where the user enters data. Once they have entered the data, I want them to use a CommandButton to do the following:
  1. Search "Sheet2", Column B2:B200000 to see if the data entered in the PON textbox already exists and provide a warning if it does and also provide msgbox that indicates that it already exists and allow for the user to exit the macro with an OK button
  2. Search "Sheet1", Column E2:E200000 to see if the data entered in the PON textbox already exists, and if so, populate the remaining TextBoxes with the corresponding data that you have already included above in your ComboBox response
    • If the data does not exist in "Sheet1", Column E2:E200000, display a msgbox that indicates it does not exist and that it needs to be entered manually
I think that once these checks are done, the CommandButton code you gave me above is fairly straight forward from the looks of it.

Thanks again!!!
 
Upvote 0
Hi @thechad.

Glad to know it worked for you.

What you are requesting is a new requirement, it is similar to the original post, but it implies new elements which will necessarily lead to a new code.

Please, create a new thread with all the details you have so that we can help you in a more practical way.

Cordially
Dante Amor
 
Upvote 0

Forum statistics

Threads
1,224,817
Messages
6,181,147
Members
453,021
Latest member
Justyna P

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