SORT

navyaa

Board Regular
Joined
Jul 7, 2002
Messages
223
I have a macro which sorts a range but when the range is empty or for some other reason it gives an error. Is there anyway i can make this work..I am pasting the code below:

Application.Goto Reference:="DTHSORT2"
Range(ActiveCell, ActiveCell.Offset([SETCNT].Value, 0)).Select
ActiveWorkbook.Names.Add Name:="REPORTED", RefersToR1C1:=Selection
Application.Goto Reference:="REPORTED"
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom
Application.Goto Reference:="DATES"
Selection.Sort Key1:=Range("B1"), Order1:=xlDescending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom

Any Suggestions?

Any help would be very appriciated....
Thank you,
Navya
 

Some videos you may like

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
55,916
Office Version
  1. 365
Platform
  1. Windows
You can add "error handling" to handle the error. Before that section of code, if you put a line in that says "On Error Resume Next", it will skip over any error and go to the next line. Then, after the sort code, you can type in "On Error Goto 0" to reset the code so it won't skip any other errors further on down the line.

If you don't want to skip all the errors, but just one error type, you can use error handling to "capture" the particular error and decide how you want to handle it (i.e. use the "Resume Next" command or print a message). Go to the following web-site for information on error handling:

http://www.barasch.com/excel/vba-errors.htm

Hope this helps!
 

Watch MrExcel Video

Forum statistics

Threads
1,122,521
Messages
5,596,650
Members
414,083
Latest member
Mrsash

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
Top