Hi, I did a little workaround based on what some co-workers said would be a good idea, which is just copy the range from the ss with data still in it into another sheet and then delete the old sheet. The code looks something like:
Sub NewQDeleteCompletedCancelled()
Dim NewQSheet As Worksheet
Dim DeleteValue1, DeleteValue2 As String
Dim rng As Range
Dim calcmode As Long
Workbooks.Open Filename:="U:\Test\NewQ.xls" 'File name
With Application
calcmode = .Calculation
.Calculation = xlCalculationManual 'turn off Excel calculation (for increased performance)
.ScreenUpdating = False 'Now the screen won't show what's happening (increased performance)
End With
DeleteValue1 = "Cancelled" 'first filter value to be deleted
DeleteValue2 = "Completed" 'second filter value to be deleted
With ActiveWorkbook.Worksheets("NewQ")
Rows("1:4").Delete 'Header to the file with unnecessary stuff in it, data starts at Row 5
.AutoFilterMode = False 'Disengage filter if it's on
.Range("V1:V" & .Rows.Count).AutoFilter Field:=1, _
Criteria1:=DeleteValue1, Operator:=xlOr, Criteria2:=DeleteValue2 'filter for statuses to be deleted
With .AutoFilter.Range
On Error Resume Next 'ignore if its broken
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _ 'add the row to the range if it's visible
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0 'ignore broken
If Not rng Is Nothing Then rng.EntireRow.Delete 'if not empty, kill it.
End With
.AutoFilterMode = False 'disengage filter
End With
Set NewQSheet = Sheets.Add 'build new worksheet
With NewQSheet
.Name = "NewQData"
.Move ActiveWorkbook.Sheets(1)
End With
Sheets("NewQ").Select 'select old worksheet
With ActiveWorkbook.Worksheets("NewQ")
.Range("A1").Resize(Cells.Find(What:="*", SearchOrder:=xlRows, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Row, _
Cells.Find(What:="*", SearchOrder:=xlByColumns, _
SearchDirection:=xlPrevious, LookIn:=xlValues).Column).Select 'select only range with data, ignore empty.
End With
Selection.Copy
Sheets("NewQData").Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _ 'keep column width
SkipBlanks:=False, Transpose:=False
ActiveSheet.Paste 'paste.
With Application
.ScreenUpdating = True 'Now you can see what Excel is doing.
.Calculation = calcmode 'Excel can count again.
.DisplayAlerts = False 'turn off fun warning boxes
End With
Sheets("NewQ").Delete 'kill sheet with empty rows
With Sheets("NewQData")
.Name = "NewQ" 'rename new sheet to old sheet name (for pivot macro I didn't feel like altering)
End With
ActiveWorkbook.Save '...save.
Application.DisplayAlerts = True 'turn warning boxes back on
End Sub
So this one is Solved. Well, sorta
It's a workaround, but it works.
Bookmarks