VBA Causing excel to open a repaired copy

JoeyGaspard

Board Regular
Joined
Jul 22, 2019
Messages
147
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

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
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
 
Upvote 0
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!!
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,214,912
Messages
6,122,200
Members
449,072
Latest member
DW Draft

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