Object variable or with block variable not set

ApolloCarrierServ

New Member
Joined
May 3, 2019
Messages
23
I have a worksheet I am trying to create a filter for. I recorded a macro with all of the filtering set to what I need. When I try to assign it to my ComboBox and run it I am getting a Run-Time Error 91 Object variable or with block variable not set. It is highlighting the section " ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort.SortFields.Clear"

Here is my Code:


Code:
Sub FOLLOWUP()
'
' FOLLOWUP Macro
'


'
If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
 ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort.SortFields.Clear
  ActiveSheet.ShowAllData
    
    ActiveSheet.Range("$D$13:$T$1880").AutoFilter Field:=4, Criteria1:= _
        "FOLLOW UP"
    ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort.SortFields.Clear
    ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort.SortFields.Add Key _
        :=Range("P14:P1880"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort.SortFields.Add Key _
        :=Range("N14:N1880"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort.SortFields.Add Key _
        :=Range("M14:M1880"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort.SortFields.Add Key _
        :=Range("H14:H1880"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort.SortFields.Add Key _
        :=Range("E14:E1880"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
    With ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort
        .Header = xlYes
        .MatchCase = False
        .Orientation = xlTopToBottom
        .SortMethod = xlPinYin
        .Apply
   
   
       End With
   End If
End Sub

Any help with this is appreciated.
 

Excel Facts

Best way to learn Power Query?
Read M is for (Data) Monkey book by Ken Puls and Miguel Escobar. It is the complete guide to Power Query.
Try this

Code:
Sub FOLLOWUP()
'
    If (ActiveSheet.AutoFilterMode And ActiveSheet.FilterMode) Or ActiveSheet.FilterMode Then
[COLOR=#0000ff]        ActiveWorkbook.Worksheets("Active Leads").Sort.SortFields.Clear[/COLOR]
        ActiveSheet.ShowAllData
        ActiveSheet.Range("$D$13:$T$1880").AutoFilter Field:=4, Criteria1:= _
            "FOLLOW UP"
        ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort.SortFields.Clear
        ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort.SortFields.Add Key _
            :=Range("P14:P1880"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort.SortFields.Add Key _
            :=Range("N14:N1880"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort.SortFields.Add Key _
            :=Range("M14:M1880"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort.SortFields.Add Key _
            :=Range("H14:H1880"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
        ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort.SortFields.Add Key _
            :=Range("E14:E1880"), SortOn:=xlSortOnValues, Order:=xlAscending, _
        DataOption:=xlSortNormal
        With ActiveWorkbook.Worksheets("Active Leads").AutoFilter.Sort
            .Header = xlYes
            .MatchCase = False
            .Orientation = xlTopToBottom
            .SortMethod = xlPinYin
            .Apply
        End With
    End If
End Sub
 
Upvote 0
That solved that error, but now I am getting Object doesn't support this property or method in this line. Does it have something to do with using an Active X ComboBox?


Code:
ActiveSheet.Range("$D$13:$T$1880").AutoFilter Field:=4, Criteria1:= _
            "FOLLOW UP"
 
Last edited:
Upvote 0
I tried your code and it works fine.
Apparently you have an error in each line.


Did you create the code?
Or did you get it somewhere else, and maybe it's for another version of excel?
What version of excel do you have?
Do you have Ms-office?
 
Upvote 0
I recorded it as a macro first then tried to attach it to the ComboBox. using this code
Code:
Private Sub ComboBox1_Change()
    If ComboBox1.ListIndex > -1 Then
       Select Case ComboBox1.Value


Case "FOLLOW UP": FOLLOWUP

End Select
End If
End Sub


I have Office 2007.
 
Last edited:
Upvote 0
The macro works.
You can upload the file to review.

You could upload a copy of your file to a free site such www.dropbox.com. Once you do that, mark it for 'Sharing' and you will be given a link to the file that you can post here. If the workbook contains confidential information, you could replace it with generic data.
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,223,882
Messages
6,175,164
Members
452,615
Latest member
bogeys2birdies

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