Userform Combobox cell data to populate textboxes values

KyleJackMorrison

Board Regular
Joined
Dec 3, 2013
Messages
107
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hello,

I'm looking for help with having my combobox that displays a list of Usernames in cells B2:B101, and once the user has selected a username to then populate all the information in the textboxes.

Here is my code so far:

VBA Code:
Private Sub UserForm_Initialize()

Sheets("PASTE DATA").Range("B3").Select
ComboBox1.List = Sheets("Paste Data").Range("B2:B101").Value
ComboBox1.Value = ActiveCell

Username_TextBox.Value = ActiveCell.Offset(0, 1)
Primary_Owner_TextBox.Value = ActiveCell.Offset(0, 2)
'ect...

End sub

So once the username has been select to put that as the active cell then the rest should fall intoplace.

Bonus:
Looking to have a 'Next Item' and 'Pervious Item' buttons so users can scroll through the different usernames.
could i use the following or would that be lazy?

VBA Code:
ActiveCell.Offset(-1, 0).Select

ActiveCell.Offset(1, 0).Select

Many thanks in advance.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
Hi,
try this updated code in your project & see if does what you want

VBA Code:
Dim wsPasteData As Worksheet

Private Sub ComboBox1_Change()
    Dim Index As Long
    
    Index = Me.ComboBox1.ListIndex

    Index = Index + 2
    With wsPasteData
        Username_TextBox.Value = IIf(Index = 1, "", .Cells(Index, 3).Value)
        Primary_Owner_TextBox.Value = IIf(Index = 1, "", .Cells(Index, 4).Value)
    End With
    
End Sub

Private Sub UserForm_Initialize()

    Set wsPasteData = ThisWorkbook.Worksheets("PASTE DATA")

    With wsPasteData
        Me.ComboBox1.List = .Range(.Range("B2"), .Range("B" & .Rows.Count).End(xlUp)).Value
    End With

End Sub

Note the variable at top of codes - This must sit at TOP of your userforms code page OUTSIDE any procedure.

Hope helpful

Dave
 
Upvote 0
Solution
Hi,
try this updated code in your project & see if does what you want

VBA Code:
Dim wsPasteData As Worksheet

Private Sub ComboBox1_Change()
    Dim Index As Long
   
    Index = Me.ComboBox1.ListIndex

    Index = Index + 2
    With wsPasteData
        Username_TextBox.Value = IIf(Index = 1, "", .Cells(Index, 3).Value)
        Primary_Owner_TextBox.Value = IIf(Index = 1, "", .Cells(Index, 4).Value)
    End With
   
End Sub

Private Sub UserForm_Initialize()

    Set wsPasteData = ThisWorkbook.Worksheets("PASTE DATA")

    With wsPasteData
        Me.ComboBox1.List = .Range(.Range("B2"), .Range("B" & .Rows.Count).End(xlUp)).Value
    End With

End Sub

Note the variable at top of codes - This must sit at TOP of your userforms code page OUTSIDE any procedure.

Hope helpful

Dave
Perfect. Just what I needed.

Quick question, When the userform initialises can I get it to default select and populate B2 as it is blank unless i select dropdown data?
 
Upvote 0
Perfect. Just what I needed.

Quick question, When the userform initialises can I get it to default select and populate B2 as it is blank unless i select dropdown data?

Just add this line at end of the Intialize event

VBA Code:
Me.ComboBox1.ListIndex = 0

Glad solution helps & appreciate feedback

Dave
 
Upvote 0

Forum statistics

Threads
1,214,935
Messages
6,122,337
Members
449,078
Latest member
skydd

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