Hi there,
I currently have a command button and when pressed a userform interface appears. However if a filter is on in the spreadsheet and I press the command button a message box appears stating that "filters are on. please turn off filters before entering information in the userform" - then the userform appears anyway regardless
I want to change this.
If filters are on and that message appears - once they press OK the userform doesn't turn up after the message. It will only turn up if filters are off.
Here is the code:
Thanks
I currently have a command button and when pressed a userform interface appears. However if a filter is on in the spreadsheet and I press the command button a message box appears stating that "filters are on. please turn off filters before entering information in the userform" - then the userform appears anyway regardless
I want to change this.
If filters are on and that message appears - once they press OK the userform doesn't turn up after the message. It will only turn up if filters are off.
Here is the code:
Code:
Private Sub UserForm_Initialize()
Dim ws As Worksheet: Set ws = Worksheets("AccessGrants")
Dim x As Long, i As Long
With ws.AutoFilter
x = .Filters.Count
For i = 1 To x
If .Filters.Item(i).On Then
MsgBox "WARNING: Filters on. Please turn all filters off before entering information.", vbExclamation, "FilterWarning"
End If
Next
End With
Dim oneCell As Range
Dim iName As Long, iUserName As Long
cboName.ColumnCount = 2
cboUsername.ColumnCount = 2
With cboName
For Each oneCell In Range("D7:D9000")
For iName = 0 To .ListCount - 1
If LCase(oneCell.Value) < LCase(.List(iName, 0)) Then Exit For
If oneCell.Value = .List(iName, 0) Then GoTo DoNotAdd
Next iName
.AddItem oneCell.Value, iName
.List(iName, 1) = oneCell.Offset(0, 1).Value
DoNotAdd:
Next oneCell
End With
With cboUsername
For iName = 0 To cboName.ListCount - 1
For iUserName = 0 To .ListCount - 1
If cboName.List(iName, 1) < .List(iUserName, 0) Then
Exit For
End If
Next iUserName
cboUsername.AddItem cboName.List(iName, 1), iUserName
.List(iUserName, 1) = iName
Next iName
For iUserName = 0 To .ListCount - 1
cboName.List(.List(iUserName, 1), 1) = iUserName
Next iUserName
End With
cboName.ColumnWidths = ";0"
cboUsername.ColumnWidths = ";0"
End Sub
Thanks