Im getting an Application defined or Object defined Error on a macro

Phantasm

Board Regular
Joined
Nov 2, 2007
Messages
58
I have no idea why I am getting an error on this. It was working fine earlier. The error happens on the line that is bold.

Rich (BB code):
Sub SHIPJOB(control As IRibbonControl)

With Sheets("JOBS IN PROCESS NEW")

If .AutoFilterMode Then .AutoFilterMode = False

.Range("A1:O1").AutoFilter 15, "x"

.AutoFilter.Range.Offset(1).Copy Sheets("SHIPPED ORDERS").Range("A" & Rows.Count).End(xlUp).Offset(1)

.AutoFilter.Range.Offset(1).EntireRow.Delete

.AutoFilterMode = False

If Not Worksheets("JOBS IN PROCESS NEW").Range("A1:O1").AutoFilter Then

Worksheets("JOBS IN PROCESS NEW").Range("A1:O1").AutoFilter

End If

ActiveWorkbook.Sheets(3).Activate

Rows("2:150").RowHeight = 16.5

End With

End Sub
 
Last edited by a moderator:

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Your code does not fail for me
Does sheet "Shipped Orders" exist? Is the spelling correct? (think it would give a different error in any case)
Test this above the line that fails
Code:
MsgBox .AutoFilter.Range.Address
 
Last edited:
Upvote 0
Your code does not fail for me
Does sheet "Shipped Orders" exist? Is the spelling correct? (think it would give a different error in any case)
Test this above the line that fails
Code:
MsgBox .AutoFilter.Range.Address


$A:$O

Is what I get. But, you know what, I formatted the sheet as a table...could that have anything to do with it?
 
Upvote 0
How about ...

Code:
  .Range("A1").CurrentRegion.AutoFilter 15, "x"
 
Upvote 0
It may well be related to the table - I suspect that was a recent change!

How can VBA offset a row when the range already includes EVERY rows in the worksheet? That is why it is failing
Code:
.AutoFilter.Range.Offset(1)
Try using this as your range - without any offset - it comprises data only
Code:
ActiveSheet.ListObjects(1).DataBodyRange

Try recording a macro when you filter the table

Read this useful guide
https://www.thespreadsheetguru.com/blog/2014/6/20/the-vba-guide-to-listobject-excel-tables
 
Last edited:
Upvote 0
If you have the whole sheet as a table, and the filter range is A: O, then when you increase the rank in a row offset(1), it exceeds the number of rows, so it sends the error.
It can be solved in this way.

Code:
Sub SHIPJOB(control As IRibbonControl)
    With Sheets("JOBS IN PROCESS NEW")
        If .AutoFilterMode Then .AutoFilterMode = False
        .Range("A:O").AutoFilter 15, "x"
        .AutoFilter.Range.Offset(1)[COLOR=#0000ff].Resize(.AutoFilter.Range.Rows.Count - 1)[/COLOR].Copy Sheets("SHIPPED ORDERS").Range("A" & Rows.Count).End(xlUp).Offset(1)
        .AutoFilter.Range.Offset(1).[COLOR=#0000ff]Resize(.AutoFilter.Range.Rows.Count - 1)[/COLOR].EntireRow.Delete
        .AutoFilterMode = False
        If Not Worksheets("JOBS IN PROCESS NEW").Range("A1:O1").AutoFilter Then
            Worksheets("JOBS IN PROCESS NEW").Range("A1:O1").AutoFilter
        End If
        ActiveWorkbook.Sheets(3).Activate
        Rows("2:150").RowHeight = 16.5
    End With
End Sub
 
Upvote 0
@DanteAmor

I cannot test but should the resize not come before the offset?

this
Code:
.AutoFilter.Range.Offset(1).Resize(.AutoFilter.Range.Rows.Count - 1)
or this??
Code:
.AutoFilter.Range.Resize(.AutoFilter.Range.Rows.Count - 1).Offset(1)
 
Upvote 0
@DanteAmor

I cannot test but should the resize not come before the offset?

this
Code:
.AutoFilter.Range.Offset(1).Resize(.AutoFilter.Range.Rows.Count - 1)
or this??
Code:
.AutoFilter.Range.Resize(.AutoFilter.Range.Rows.Count - 1).Offset(1)


Do not worry, I can test it for you.
This form is correct:


Code:
.AutoFilter.Range.Offset(1).Resize(.AutoFilter.Range.Rows.Count - 1).Copy

This form is wrong:


Code:
.AutoFilter.Range.Resize(.AutoFilter.Range.Rows.Count - 1).Offset(1)
 
Upvote 0
If you have the whole sheet as a table, and the filter range is A: O, then when you increase the rank in a row offset(1), it exceeds the number of rows, so it sends the error.

A small detail, return this "A:O" to this "A1:O1" on the next line:

Code:
.Range("A1:O1").AutoFilter 15, "x"
 
Last edited:
Upvote 0
deleted by Yongle
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,915
Messages
6,122,217
Members
449,074
Latest member
cancansova

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