ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Populate List or Combo box based on User ID (https://www.excelbanter.com/excel-programming/407116-populate-list-combo-box-based-user-id.html)

Steve[_4_]

Populate List or Combo box based on User ID
 
Hello all. I have a piece of code that captured the user's Windows
login id by using environ("UserName"). I have a block of Data in
Sheet1. In column A, I have a list of User ID's. In column B, I have
a Sale # that I would like populated in the list or combo box. So, if
I login, the value in the environ("UserName") variable is "Steve". I
would like vba to scan column A for Steve, and when it finds it,
populate the list box with the value in Col B, noting that there may
be multiple instances of "Steve" in Col A. So therefore they may be
more than one item populated in the list box. Can this be done??
Thanks!!

JLGWhiz

Populate List or Combo box based on User ID
 
This goes in project code module1:

Sub Ufshw()
UserForm1.Show
End Sub

These two goes in the UserForm code module:

Private Sub UserForm_Initialize()
lr = Cells(Rows.Count, 1).End(xlUp).Row
uid = Environ("UserName")

For Each c In Sheets(1).Range("A1:A" & lr)
If Not c Is Nothing Then
If LCase(c.Value) = LCase(uid) Then
ListBox1.AddItem c.Offset(0, 1).Value
End If
End If
Next
End Sub

Private Sub ListBox1_Click()
Unload UserForm1
End Sub

Now, if you want to do anything with the item selected
in the ListBox, you will have to add that code to the
ListBox1 click event.

"Steve" wrote:

Hello all. I have a piece of code that captured the user's Windows
login id by using environ("UserName"). I have a block of Data in
Sheet1. In column A, I have a list of User ID's. In column B, I have
a Sale # that I would like populated in the list or combo box. So, if
I login, the value in the environ("UserName") variable is "Steve". I
would like vba to scan column A for Steve, and when it finds it,
populate the list box with the value in Col B, noting that there may
be multiple instances of "Steve" in Col A. So therefore they may be
more than one item populated in the list box. Can this be done??
Thanks!!



All times are GMT +1. The time now is 10:15 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com