Help with a VBA code

7 views
Skip to first unread message

James Powell

unread,
Feb 19, 2025, 4:42:24 AMFeb 19
to excel vba
Hi All 

i have the below VBA code and i am running into a problem. I get no errors when compiling the code. The issue is that i have a users sheet and one is Active the other is not. 
I have a userform that is ment to display the users that need approval but it is not displaying htem in the list box i created. I have checked and the it is called lstUsers and the combo box does list the roles.

Can anybody see anything that i am missing?

Private Sub UserForm_Initialize()
    Dim wsUsers As Worksheet
    Dim lastRow As Long, i As Long

    ' Set Users sheet
    Set wsUsers = ThisWorkbook.Sheets("Users")
   
    ' Clear existing list
    Me.lstUsers.Clear
    Me.cmbRole.Clear
   
    ' Find last row
    lastRow = wsUsers.Cells(Rows.Count, 1).End(xlUp).Row
   
    ' Add only pending users to ListBox
    For i = 2 To lastRow
        If wsUsers.Cells(i, 4).Value = "FALSE" Then
            Me.lstUsers.AddItem wsUsers.Cells(i, 1).Value
        End If
    Next i

    ' Add role options to ComboBox
    Me.cmbRole.AddItem "Customer"
    Me.cmbRole.AddItem "Purchaser"
    Me.cmbRole.AddItem "Admin"
   
    ' Default selection
    Me.cmbRole.ListIndex = 0
End Sub
Reply all
Reply to author
Forward
0 new messages