Dear Sir/Madam,
I have about 1M rows. After filtering I have about 150K areas.
Deleting the visible cells after filtering is not working.
Your help would be greatly appreciated.
Kind Regards
Biz
I have about 1M rows. After filtering I have about 150K areas.
Deleting the visible cells after filtering is not working.
Code:
Dim aStartTime
Const DblSpace As String = vbNewLine & vbNewLine
Const CoName As String = "Silence"
Dim wbTarget As Worksheet
Dim bErrorHandle As Boolean
Sub Test()
Dim Rng As Range, rngNew As Range, rngVis As Range, rCells As Range
Dim area As Range
Dim areaCount As Long
Dim selectedRange As Range
' '~~> Speeding Up VBA Code
Call SpeedUp(False)
Set selectedRange = Range("A3:A600000").SpecialCells(xlCellTypeVisible)
Set wbTarget = Sheets("Test")
Set Rng = wbTarget.Range("$A$2:$L$600000")
Set rngNew = Rng.Resize(Rng.Rows.Count - 1, 1).Offset(1, 0)
areaCount = 1
Debug.Print "# of Area(s):";
If selectedRange.Areas.Count = 1 Then
Debug.Print 1
For Each rCells In selectedRange 'loop through each cell in the selected range
Debug.Print rCells.Address 'do whatever
Next
Else
Debug.Print selectedRange.Areas.Count
For Each area In selectedRange 'more than 1 selected area
Debug.Print "Area#: " & areaCount
If rngVis Is Nothing Then
Set rngVis = area
Else
Set rngVis = Application.Union(rngVis, area)
End If
rngVis.EntireRow.Delete
' '~~> Speeding Up VBA Code
Call SpeedUp(True)
If bErrorHandle = False Then
MsgBox "Time taken: " & Format(Now() - aStartTime, "h:mm:ss") & vbNewLine _
& DblSpace & " You're good to go!" & DblSpace & _
CoName & Chr(32) & Chr(169) & Chr(32) & Year(Date), vbInformation, "Excellent"
End If
End Sub
'#### SpeedUp (False) - Speeds the VBA Code #####
'#### SpeedUp (True) - Slows down the VBA Code ####
Public Function SpeedUp(Optional bSpeed As Boolean = True)
With Application
.ScreenUpdating = bSpeed 'Prevent screen flickering
.Calculation = IIf(bSpeed, xlAutomatic, xlCalculationManual) 'Preventing calculation
.DisplayAlerts = bSpeed 'Turn OFF alerts
.EnableEvents = bSpeed 'Prevent All Events
'.Cursor = IIf(bSpeed, xlDefault, xlWait) 'Prevent Hour Glass
'.StatusBar = IIf(bSpeed, vbNullString, "Please wait...")
End With
End Function
Your help would be greatly appreciated.
Kind Regards
Biz