Error opening file after sorting, saving, and closing

kweaver

Well-known Member
Joined
May 12, 2009
Messages
2,940
Office Version
  1. 365
I have an Excel workbook with a tab named "Master". I have a sorting button that calls this routine:

Code:
Sub SortByEmpNo()
 Sheets("Master").Activate
 With ActiveSheet.Sort
 .SortFields.Add Key:=Range("A10"), Order:=xlAscending
 .SetRange Range("A10:G1013")
 .Header = xlYes
 .Apply
 End With
End Sub

That sorts based on column A with the header in A10. It sorts properly.

When I save the file, close it, and reopen it, I get this error:

error1.jpg


clicking on Yes:

error2.jpg


Clicking to view the error:

error3.jpg


While I'd like to view the error, I can't. However, if I just ignore this (since it won't show it to me), resave the file, close it, and reopen it...there's no error!!

(a) how do I get to view the error and (b) bypass this somehow so that the file is "fixed" [for whatever reason] and opens right away the next time I open it???

Thanks in advance.
 

Excel Facts

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.
I suspect the error is because you are not clearing the sort fields, so you are just creating more & more of them.
Try
Code:
Sub SortByEmpNo()
 Sheets("Master").Activate
 With ActiveSheet.Sort
 [COLOR=#ff0000].SortFields.Clear[/COLOR]
 .SortFields.Add Key:=Range("A10"), Order:=xlAscending
 .SetRange Range("A10:G1013")
 .Header = xlYes
 .Apply
 End With
End Sub
 
Upvote 0
You nailed it, of course. So nice to hear from experts here -- and so quickly as well! Thanks!!!
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

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