Application defined or object defined error

dpaton05

Well-known Member
Joined
Aug 14, 2018
Messages
2,392
Office Version
  1. 365
  2. 2016
Platform
  1. Windows
I try to run this code and all it says it application defined or object defined error and it highlights this row
Code:
Workbooks(DocYearName).Worksheets(Combo).Range("A5").CurrentRegion.Select key1:=Range("A3"), order1:=xlAscending, header:=xlYes
However, I don't think it is a problem with this line of code as it used to work and now it has stopped, despite having done nothing to the particular line of code.
DocYearName and Combo are variables.

Please help me as I am totally stumped.

Thanks,
Dave
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
It has stopped despite having done nothing to the particular line of code

You have inadvertently amended that line ;)

BAD
Workbooks(DocYearName).Worksheets(Combo).Range("A5").CurrentRegion.Select key1:=Range("A3"), order1:=xlAscending, Header:=xlYes

GOOD
Workbooks(DocYearName).Worksheets(Combo).Range("A5").CurrentRegion.Sort key1:=Range("A3"), order1:=xlAscending, Header:=xlYes
 
Last edited:
Upvote 0
You have inadvertently amended that line ;)

GOOD
Workbooks(DocYearName).Worksheets(Combo).Range("A4").CurrentRegion.Sort key1:=Range("A3"), order1:=xlAscending, Header:=xlYes

Thanks, I knew it was something simple like that but it still isn't working. I am still getting an error, The sort reference is not valid. Make sure that it's within the data you want to sort, and the first sort box isn't the same or blank.

The sort is occuring in a range and will be sorted from earliest to latest. It is being sorted by date. The data to be sorted starts in A4 and goes down from there. Above that are headers (A3) and other bits and pieces that won't be part of the sort process. I have columns that need sorting with the date up to column P.

This is the code I have put in but am now getting the above error with.

Code:
        Workbooks(DocYearName).Worksheets(Combo).Range("A4").CurrentRegion.sort Key:=Range("A1"), order1:=xlAscending, header:=xlYes

Any help would be greatly appreciated.
 
Upvote 0
Key:=Range("A1")

Is A1 inside your sort range?
A4 perhaps?
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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