Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 184
Default 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!!
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,986
Default 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!!

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Populate List or Combo box based on User ID Steve[_4_] Excel Programming 0 March 4th 08 08:29 PM
Populate one combo box based on the selection of another combo box Alex Excel Programming 8 April 19th 07 06:40 PM
Populate List / Combo Box Dave C Excel Discussion (Misc queries) 1 October 6th 05 08:15 PM
Populate a Combo or List Box Jonathan Excel Programming 8 September 19th 05 04:08 PM
Populate Combo Box With Filtered List Kinne Excel Programming 2 August 11th 03 12:23 PM


All times are GMT +1. The time now is 07:28 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"