Return text in column after selecting an text in Combobox using VBA coding

mosesena

New Member
Joined
Oct 7, 2013
Messages
4
How can I return text on confirmation message box from selecting text from a Combobox linked to adjacent cell in a worksheet using a Userform.
 

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
How can I return text on confirmation message box from selecting text from a Combobox linked to adjacent cell in a worksheet using a Userform.

Your question is not clear to me(and I am guessing others as well). Can you please provide more description of your setup and what you want to do with it?
 
Upvote 0
Your question is not clear to me(and I am guessing others as well). Can you please provide more description of your setup and what you want to do with it?

I have two columns of data. The first contains 'names' and the second contains 'passwords'. The Userform is completed with information plus a combobox displaying 'names'. When the command button is clicked, the information is updated to a database and the 'name' selected in the combobox should display the matching 'password' on a message box.

The question is how do I code the combobox element of the userform to display on a message box, the 'password' matching the 'name' selected?
 
Upvote 0
You could populate the combobox with both columns, make the password column the bound column and hide it.

Then the Value property of the combobox will return the password for the name selected.
Code:
Private Sub UserForm_Initialize
    With ComboBox1
        .BoundColumn = 2
        .ColumnCount = 2
        .ColumnWidths ="50pt;0pt"
        .List = Range("A1:B20").Value   ' A1:B20 houses names (column A) and passwords (column B)
    End With
End Sub


Private Sub CommandButton1_Click()
     If ComboBox1.ListIndex <> -1 Then
          MsgBox Combobox1.Column(0) & "'s password is " & ComboBox1.Value
     End If
End Sub
 
Upvote 0
You could populate the combobox with both columns, make the password column the bound column and hide it.

Then the Value property of the combobox will return the password for the name selected.
Code:
Private Sub UserForm_Initialize
    With ComboBox1
        .BoundColumn = 2
        .ColumnCount = 2
        .ColumnWidths ="50pt;0pt"
        .List = Range("A1:B20").Value   ' A1:B20 houses names (column A) and passwords (column B)
    End With
End Sub


Private Sub CommandButton1_Click()
     If ComboBox1.ListIndex <> -1 Then
          MsgBox Combobox1.Column(0) & "'s password is " & ComboBox1.Value
     End If
End Sub
That certainly works...Thanks. The other part of it is ....if a user selects a name and password, that name and password should not be available for the next user. Question is how do I code it?
 
Upvote 0
You could remove the name and password.
Code:
ComboBox1.RemoveItem ComboBox1.ListIndex
 
Upvote 0

Forum statistics

Threads
1,223,155
Messages
6,170,405
Members
452,325
Latest member
BlahQz

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