FalconFlyer

New Member
Joined
May 18, 2015
Messages
30
I need some help troubleshooting an error. I have an spreadsheet with some code and it runs with no errors. I saved it and opened it the next day and got the "Excel found unreadable content. do you want to recover the contents?". It then states "Removed Records: Sorting from /xl/worksheets/sheet4.xml part". I looked in VBE and I do not have a Sheet4. Even with this removed, the code seems to work fine, but I'd like to resolve the error. I am assuming the problem is with the sorting code. I used the macro recorder to help, so I am not sure why it is wrong. Any advice would be appreciated. TIA.

<code>
Code:
Sub RunAll()
'
' Macro2 Macro
'

'
    Application.ScreenUpdating = False

    Worksheets("Data").Visible = True
    Sheets("Dataset").Select
    Cells.Select
    Selection.ClearContents
    Range("A1").Select
    
    Sheets("Data").Select
    Range("Table_Query_from_IQS[#All]").Select
    Selection.Copy
    Sheets("Dataset").Select
    Range("A1").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    Worksheets("Data").Visible = False
    
'Sort before cleaning data
LastRow = Range("A" & Rows.Count).End(xlUp).Row
With Sheets("Dataset").Sort
     .SortFields.Add Key:=Range("A1"), Order:=xlAscending
     .SortFields.Add Key:=Range("M1"), Order:=xlAscending
     .SetRange Range("A1:U" & LastRow)
     .Header = xlYes
     .Apply
    End With
</code>
 

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.
The error message is not clear, when it says "sheet4.xml" it means the 4th sheet in the workbook, not codename Sheet4.
The problem is because you are not removing the existing sort fields in the code, but simply adding them every time, so eventually you get so many that it causes a problem.
Try
Code:
With Sheets("Dataset").Sort
    [COLOR=#ff0000] .SortFields.Clear[/COLOR]
     .SortFields.Add Key:=Range("A1"), Order:=xlAscending
     .SortFields.Add Key:=Range("M1"), Order:=xlAscending
     .SetRange Range("A1:U" & LastRow)
     .Header = xlYes
     .Apply
End With
 
Upvote 0

Forum statistics

Threads
1,215,793
Messages
6,126,936
Members
449,349
Latest member
Omer Lutfu Neziroglu

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