VBA Causing excel to open a repaired copy

JoeyGaspard

Board Regular
Joined
Jul 22, 2019
Messages
134
I created an excel file with some vba in it, everytime i close it, it wants me to save a copy, and everytime I open it, it gives me this message:

1617723599139.png


and when I click yes, it gives me this:

1617723633951.png

This is the error log text:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<recoveryLog xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main"><logFileName>error095320_01.xml</logFileName><summary>Errors were detected in file 'https://houseofraeford-my.sharepoin...m/Documents/Desktop/AccountingTimeReport.xlsb'</summary><removedRecords><removedRecord>Removed Records: Sorting from /xl/worksheets/sheet6.bin part</removedRecord><removedRecord>Removed Records: Sorting from /xl/worksheets/sheet7.bin part</removedRecord><removedRecord>Removed Records: Sorting from /xl/worksheets/sheet8.bin part</removedRecord><removedRecord>Removed Records: Sorting from /xl/worksheets/sheet9.bin part</removedRecord><removedRecord>Removed Records: Sorting from /xl/worksheets/sheet10.bin part</removedRecord><removedRecord>Removed Records: Sorting from /xl/worksheets/sheet11.bin part</removedRecord><removedRecord>Removed Records: Sorting from /xl/worksheets/sheet12.bin part</removedRecord><removedRecord>Removed Records: Sorting from /xl/worksheets/sheet13.bin part</removedRecord></removedRecords></recoveryLog>

And below is my vba (I know its crude but it was working fine), I think it is the sorting, but Im not sure how to fix it as I have to have it?

VBA Code:
Sub ProcessTime()

'Refresh Data Connection

ThisWorkbook.RefreshAll

'Copy Timereport-utf8 to Report
Sheets("timereport").Select
Range(Range("A2:G2"), Range("A2:G2").End(xlDown)).Copy
Worksheets("Report").Range("A1").PasteSpecial Paste:=xlPasteValues


' Remove columns From Report
   
   Sheets("Report").Select
    Range("A:A,C:C,G:G").Select
    Range("G1").Activate
    Selection.Delete Shift:=xlToLeft
    Range("A1").Select
   
'Copy Report to Calculation

    Sheets("Report").Select
    Columns("A:D").Select
    Selection.Copy
    Sheets("Calculation").Select
    Range("A1").Select
    ActiveSheet.Paste
    Range("A1").Select


    With Sheets("Calculation")
   
      .AutoFilterMode = False
      .Range("A1").AutoFilter 1, "197565"
      .AutoFilter.Range.Columns("A:D").Offset(1).Copy Sheets("AngieK").Range("A1")
      .AutoFilterMode = False
   End With
   
    With Sheets("Calculation")
      .AutoFilterMode = False
      .Range("A1").AutoFilter 1, "197613"
      .AutoFilter.Range.Columns("A:D").Offset(1).Copy Sheets("AdriannaP").Range("A1")
      .AutoFilterMode = False
   End With
  
   With Sheets("Calculation")
      .AutoFilterMode = False
      .Range("A1").AutoFilter 1, "197460"
      .AutoFilter.Range.Columns("A:D").Offset(1).Copy Sheets("DenittaA").Range("A1")
      .AutoFilterMode = False
   End With
  
   With Sheets("Calculation")
      .AutoFilterMode = False
      .Range("A1").AutoFilter 1, "197634"
      .AutoFilter.Range.Columns("A:D").Offset(1).Copy Sheets("KimR").Range("A1")
      .AutoFilterMode = False
   End With
  
   With Sheets("Calculation")
      .AutoFilterMode = False
      .Range("A1").AutoFilter 1, "197564"
      .AutoFilter.Range.Columns("A:D").Offset(1).Copy Sheets("KristiS").Range("A1")
      .AutoFilterMode = False
   End With
  
   With Sheets("Calculation")
      .AutoFilterMode = False
      .Range("A1").AutoFilter 1, "197563"
      .AutoFilter.Range.Columns("A:D").Offset(1).Copy Sheets("KristieJ").Range("A1")
      .AutoFilterMode = False
   End With
  
   With Sheets("Calculation")
      .AutoFilterMode = False
      .Range("A1").AutoFilter 1, "19999"
      .AutoFilter.Range.Columns("A:D").Offset(1).Copy Sheets("LeahC").Range("A1")
      .AutoFilterMode = False
   End With

    With Sheets("Calculation")
      .AutoFilterMode = False
      .Range("A1").AutoFilter 1, "4"
      .AutoFilter.Range.Columns("A:D").Offset(1).Copy Sheets("RachelO").Range("A1")
      .AutoFilterMode = False
   End With



    'Sort Column Data
   
    Sheets("LeahC").Select
    With ActiveSheet.Sort
     .SortFields.Add Key:=Range("B1"), Order:=xlAscending
          .SetRange Range("A1:D50")
     .Header = xlNo
     .Apply
     Columns("B:B").Select
    Selection.NumberFormat = "m/d/yy h:mm;@"
    End With
     
Sheets("KristieJ").Select
    With ActiveSheet.Sort
     .SortFields.Add Key:=Range("B1"), Order:=xlAscending
          .SetRange Range("A1:D50")
     .Header = xlNo
     .Apply
     Columns("B:B").Select
    Selection.NumberFormat = "m/d/yy h:mm;@"
End With

Sheets("KristiS").Select
    With ActiveSheet.Sort
     .SortFields.Add Key:=Range("B1"), Order:=xlAscending
          .SetRange Range("A1:D50")
     .Header = xlNo
     .Apply
     Columns("B:B").Select
    Selection.NumberFormat = "m/d/yy h:mm;@"
End With

Sheets("AngieK").Select
    With ActiveSheet.Sort
     .SortFields.Add Key:=Range("B1"), Order:=xlAscending
          .SetRange Range("A1:D50")
     .Header = xlNo
     .Apply
     Columns("B:B").Select
    Selection.NumberFormat = "m/d/yy h:mm;@"
End With

Sheets("DenittaA").Select
    With ActiveSheet.Sort
     .SortFields.Add Key:=Range("B1"), Order:=xlAscending
          .SetRange Range("A1:D50")
     .Header = xlNo
     .Apply
     Columns("B:B").Select
    Selection.NumberFormat = "m/d/yy h:mm;@"
End With

Sheets("KimR").Select
    With ActiveSheet.Sort
     .SortFields.Add Key:=Range("B1"), Order:=xlAscending
          .SetRange Range("A1:D50")
     .Header = xlNo
     .Apply
     Columns("B:B").Select
    Selection.NumberFormat = "m/d/yy h:mm;@"
End With

Sheets("AdriannaP").Select
    With ActiveSheet.Sort
     .SortFields.Add Key:=Range("B1"), Order:=xlAscending
          .SetRange Range("A1:D50")
     .Header = xlNo
     .Apply
     Columns("B:B").Select
    Selection.NumberFormat = "m/d/yy h:mm;@"
End With

Sheets("RachelO").Select
    With ActiveSheet.Sort
     .SortFields.Add Key:=Range("B1"), Order:=xlAscending
          .SetRange Range("A1:D50")
     .Header = xlNo
     .Apply
     Columns("B:B").Select
    Selection.NumberFormat = "m/d/yy h:mm;@"
End With

Sheets("Totals").Select



End Sub

Any help is greatly appreciated!!
 

Excel Facts

VLOOKUP to Left?
Use =VLOOKUP(A2,CHOOSE({1,2},$Z$1:$Z$99,$Y$1:$Y$99),2,False) to lookup Y values to left of Z values.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,790
Office Version
  1. 365
Platform
  1. Windows
When sorting like that you need to clear the existing sort like
VBA Code:
    With ActiveSheet.Sort
     .SortFields.Clear
     .SortFields.Add Key:=Range("B1"), Order:=xlAscending
          .SetRange Range("A1:D50")
     .Header = xlNo
     .Apply
     Columns("B:B").Select
    Selection.NumberFormat = "m/d/yy h:mm;@"
    End With
 

JoeyGaspard

Board Regular
Joined
Jul 22, 2019
Messages
134
When sorting like that you need to clear the existing sort like
VBA Code:
    With ActiveSheet.Sort
     .SortFields.Clear
     .SortFields.Add Key:=Range("B1"), Order:=xlAscending
          .SetRange Range("A1:D50")
     .Header = xlNo
     .Apply
     Columns("B:B").Select
    Selection.NumberFormat = "m/d/yy h:mm;@"
    End With
Worked perfectly! Thank you!!
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,790
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,130,048
Messages
5,639,769
Members
417,111
Latest member
buyukbang

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