Here's a bit of a puzzler. I built a code to do the following steps:
1. Apply a filter
2. Copy visible cells
3. Paste the visible cells to a new sheet
4. Rename the new sheet
5. Migrate back to the old sheet and delete the visible rows (thus removing them from the unfiltered data)
Trouble is, when the process is done, the active range (as determined by Ctrl+Shift+End) is showing row 1,000,000 (when I only copied over a few thousand rows). Is there something I can do to prevent this from happening?
Here's a sample of the code. Any help is always appreciated.
1. Apply a filter
2. Copy visible cells
3. Paste the visible cells to a new sheet
4. Rename the new sheet
5. Migrate back to the old sheet and delete the visible rows (thus removing them from the unfiltered data)
Trouble is, when the process is done, the active range (as determined by Ctrl+Shift+End) is showing row 1,000,000 (when I only copied over a few thousand rows). Is there something I can do to prevent this from happening?
Here's a sample of the code. Any help is always appreciated.
Code:
Sub lite360()
ActiveSheet.UsedRange.AutoFilter Field:=11, Criteria1:="-"
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets.Add After:=ActiveSheet
ActiveSheet.Paste
Selection.Columns.AutoFit
Sheets("Sheet2").Select
Sheets("Sheet2").Name = "ZERO BALANCE"
Sheets("Sheet1").Select
Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Application.CutCopyMode = False
Selection.EntireRow.Delete
ActiveSheet.UsedRange.AutoFilter Field:=4
ActiveSheet.UsedRange.AutoFilter Field:=11
ActiveSheet.UsedRange.AutoFilter Field:=13, Criteria1:="O"
Range("A1").Select
Selection.SpecialCells(xlCellTypeVisible).Select
Selection.Copy
Sheets.Add After:=ActiveSheet
ActiveSheet.Paste
Selection.Columns.AutoFit
Sheets("Sheet3").Select
Sheets("Sheet3").Name = "OP"
Sheets("Sheet1").Select
Range("A2").Select
Range(Selection, ActiveCell.SpecialCells(xlLastCell)).Select
Application.CutCopyMode = False
Selection.EntireRow.Delete
End Sub