Hi,
I rewrote it a bit and added turned of screenupdating and calculation, etc. during the procedure (which you can integrate in your first script instead if needed). Added a parameter t
Try this:
Sub test()
Call DeleteEveryNthRow 'every 2nd row on activesheet
'Call DeleteEveryNthRow(, 3) 'every 3rd row on activesheet
'Call DeleteEveryNthRow(Sheets("Sheet1"), 3) 'every 3rd row on Sheet1
'Call DeleteEveryNthRow(Sheets("Sheet3"), 5) 'every 5th row on Sheet3
End Sub
Public Sub DeleteEveryNthRow(Optional ws As Worksheet = Nothing, Optional N As Long = 2)
Dim lCalc As Long, rngDel As Range, rngRow As Range
If ws Is Nothing Then Set ws = ActiveSheet
'optimize
With Application
.EnableEvents = False
.DisplayAlerts = False
lCalc = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With
For Each rngRow In ws.UsedRange.Rows
If (rngRow.Row Mod N) = 0 Then
If rngDel Is Nothing Then
Set rngDel = rngRow
Else
Set rngDel = Union(rngRow, rngDel)
End If
End If
Next rngRow
If Not rngDel Is Nothing Then rngDel.EntireRow.Delete
'restore settings
With Application
.EnableEvents = True
.DisplayAlerts = True
.Calculation = lCalc
.ScreenUpdating = True
End With
End Sub
Best,
berlan
Bookmarks