All2Cheesy
Board Regular
- Joined
- Mar 4, 2015
- Messages
- 127
Hi all,
I've got a macro which deletes rows which do not have a cell equal to "kilogram", while also inserting a blank row after each instance of "99999". To do this I am using multiple loops, and as such running this macro takes quite a bit of time. Is there any way I can clean up my code to have my macro run a bit quicker? Thanks!
I've got a macro which deletes rows which do not have a cell equal to "kilogram", while also inserting a blank row after each instance of "99999". To do this I am using multiple loops, and as such running this macro takes quite a bit of time. Is there any way I can clean up my code to have my macro run a bit quicker? Thanks!
Code:
Sub DELROWs()
Dim couNter As Long
Dim RowCount As Long
'Disable additional features
With Application
.ScreenUpdating = False
.Calculation = xlManual
.EnableEvents = False
.DisplayAlerts = False
End With
RowCount = Range("B65536").End(xlUp).Row
couNter = 1
Do Until couNter > RowCount
If Range("F" & couNter).Value <> "Kilogram" Then
Range("F" & couNter).EntireRow.Delete
RowCount = RowCount - 1
couNter = couNter - 1
End If
couNter = couNter + 1
Loop
RowCount = Range("B65536").End(xlUp).Row
couNter = 1
Do Until couNter > RowCount
If Range("D" & couNter).Value = 99999 Then
Range("D" & couNter + 1).EntireRow.Insert
RowCount = RowCount + 1
couNter = couNter + 1
End If
couNter = couNter + 1
Loop
Application.ScreenUpdating = True
'Disable additional features
With Application
.ScreenUpdating = True
.Calculation = xlAutomatic
.EnableEvents = True
.DisplayAlerts = True
End With
End Sub