Hello Everyone,
I should start by saying I've only a very basic grasp of VBA.
Some of the guys on this forum have helped me with some VBA code to delete unwanted rows of data from a spreadsheet, which does exactly what it should so thanks for that.
Only thing is that i've run it with the same source data over and over in testing it may take 3 minutes to process or 10 minutes. I can't understand what would cause it to be so drastically different.
The code is here -
Sub MainRoutineA()
Dim ws As Worksheet
Dim Rng As Range
Dim lastRow As Long
Application.ScreenUpdating = False
Set ws = ActiveWorkbook.Sheets("FY Budget from ART")
lastRow = ws.Range("I" & ws.rows.Count).End(xlUp).Row
Set Rng = ws.Range("I5:I" & lastRow)
With Rng
.AutoFilter Field:=1, Criteria1:="<>" & Worksheets("User Information").Range("I34").Value
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
EndWith
ws.AutoFilterMode = False
Application.ScreenUpdating = True
EndSub
In the workbook, a user will select their name from a dropdown on "User Information" - "I34".
The Code will look down column I and remove any instances where that users name doesn't exist.
Is there any tips for using this type of code that would potentially speed it up or can you see any red flags that cause known speed issues in the above code?
If it helps the source data will average about 11,000 rows and once run cut the data to maybe 250-750 Rows.
As always in advance.
Richard
I should start by saying I've only a very basic grasp of VBA.
Some of the guys on this forum have helped me with some VBA code to delete unwanted rows of data from a spreadsheet, which does exactly what it should so thanks for that.
Only thing is that i've run it with the same source data over and over in testing it may take 3 minutes to process or 10 minutes. I can't understand what would cause it to be so drastically different.
The code is here -
Sub MainRoutineA()
Dim ws As Worksheet
Dim Rng As Range
Dim lastRow As Long
Application.ScreenUpdating = False
Set ws = ActiveWorkbook.Sheets("FY Budget from ART")
lastRow = ws.Range("I" & ws.rows.Count).End(xlUp).Row
Set Rng = ws.Range("I5:I" & lastRow)
With Rng
.AutoFilter Field:=1, Criteria1:="<>" & Worksheets("User Information").Range("I34").Value
.SpecialCells(xlCellTypeVisible).EntireRow.Delete
EndWith
ws.AutoFilterMode = False
Application.ScreenUpdating = True
EndSub
In the workbook, a user will select their name from a dropdown on "User Information" - "I34".
The Code will look down column I and remove any instances where that users name doesn't exist.
Is there any tips for using this type of code that would potentially speed it up or can you see any red flags that cause known speed issues in the above code?
If it helps the source data will average about 11,000 rows and once run cut the data to maybe 250-750 Rows.
As always in advance.
Richard
Last edited: