Hi all,
My macro runs and saves a created workbook from the macro workbook. But the file that is saved corrupt and excel has to ask if the user wants to recover data whenever these files are produced.
I have gone over all my code, and I suspect that the way I am sorting the data is buggy.
Is my syntax correct? Could this be a cause of this issue?
I set the references to mainSh3 with:
My macro runs and saves a created workbook from the macro workbook. But the file that is saved corrupt and excel has to ask if the user wants to recover data whenever these files are produced.
I have gone over all my code, and I suspect that the way I am sorting the data is buggy.
Is my syntax correct? Could this be a cause of this issue?
Code:
Set sort1 = Range("A1:AJ1")
Set sort2 = Range("A1")
Set sort3 = Range("G1")
Set sort4 = Range("H1")
mainSh3.Range("A1").Value = "Match?"
mainSh3.Range("B1").Value = "PlnTaxSrc"
mainSh3.Range("C1").Value = "Current"
mainSh3.Range("D1").Value = "Compare"
With mainSh3.Sort
.SortFields.Add Key:=sort2, Order:=xlDescending
.SortFields.Add Key:=sort3, Order:=xlDescending
.SortFields.Add Key:=sort4, Order:=xlDescending
.SetRange sort1
.Header = xlYes
.Apply
End With
I set the references to mainSh3 with:
Code:
Set mainWB = Workbooks.Add
mainWB.Sheets.Add After:=Sheet1, Count:=2
Set mainSh1 = mainWB.Worksheets(1)
Set mainSh2 = mainWB.Worksheets(2)
Set mainSh3 = mainWB.Worksheets(3)