VBA userform warning for filters still shows interface

sdhutty

Board Regular
Joined
Jul 15, 2016
Messages
207
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:

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 :)
 

Excel Facts

How to find 2nd largest value in a column?
MAX finds the largest value. =LARGE(A:A,2) will find the second largest. =SMALL(A:A,3) will find the third smallest

Forum statistics

Threads
1,223,711
Messages
6,174,025
Members
452,542
Latest member
Bricklin

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