Godders199
Active Member
- Joined
- Mar 2, 2017
- Messages
- 313
- Office Version
- 2013
Hello, I have the following code which currently works perfectly and in a timely manner, I have had to add a filter in to ensure that any row that contains the word "testing" is not removed even if the adviser is on the list of not needing a check. this appears to have slowed down the functionality of this VBA, i am wondering if there is a more efficient way to code this into the VBA.
Additional code is in bold below in part two .
First part of the code creates the list i need of advisers not needing any checks., second part removes those advisers from the list.
Sub checkscompleted()
'create list of advisers not needing a check'
Sheets("checks").Select
Dim sh4 As Worksheet
Set sh4 = Worksheets("checks")
With sh4.Range("a1").CurrentRegion
Rows("2:2").Select
.AutoFilter Field:=21, Criteria1:="<=0", _
Operator:=xlAnd
End With
Columns("a:a").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("checks completed").Select
Range("a1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("checks").ShowAllData
'remove deselected advisers from allocation'
Dim rngFound As Range, rngToDelete As Range
Dim strFirstAddress As String
Dim varList As Variant
Dim lngCounter As Long
Dim UsdRws As Long
UsdRws = Sheets("checks completed").Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
Sheets("submissions").Select
Cells.Select
ActiveSheet.Range("A:AJ").AutoFilter Field:=25, Criteria1:= _
"<>*testing*", Operator:=xlAnd
varList = Sheets("checks completed").Range("A1:A" & UsdRws).Value
For lngCounter = LBound(varList) To UBound(varList)
With ActiveSheet.Range("d:d")
Set rngFound = .Find( _
What:=varList(lngCounter, 1), _
Lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=True _
)
If Not rngFound Is Nothing Then
If rngToDelete Is Nothing Then
Set rngToDelete = rngFound
Else
Set rngToDelete = Application.Union(rngToDelete, rngFound)
End If
strFirstAddress = rngFound.Address
Set rngFound = .FindNext(After:=rngFound)
Do Until rngFound.Address = strFirstAddress
Set rngToDelete = Application.Union(rngToDelete, rngFound)
Set rngFound = .FindNext(After:=rngFound)
Loop
End If
End With
Next lngCounter
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
Range("a1").Select
Sheets("instructions").Select
End Sub
thanks for any help.
Additional code is in bold below in part two .
First part of the code creates the list i need of advisers not needing any checks., second part removes those advisers from the list.
Sub checkscompleted()
'create list of advisers not needing a check'
Sheets("checks").Select
Dim sh4 As Worksheet
Set sh4 = Worksheets("checks")
With sh4.Range("a1").CurrentRegion
Rows("2:2").Select
.AutoFilter Field:=21, Criteria1:="<=0", _
Operator:=xlAnd
End With
Columns("a:a").Select
Application.CutCopyMode = False
Selection.Copy
Sheets("checks completed").Select
Range("a1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("checks").ShowAllData
'remove deselected advisers from allocation'
Dim rngFound As Range, rngToDelete As Range
Dim strFirstAddress As String
Dim varList As Variant
Dim lngCounter As Long
Dim UsdRws As Long
UsdRws = Sheets("checks completed").Range("A" & Rows.Count).End(xlUp).Row
Application.ScreenUpdating = False
Sheets("submissions").Select
Cells.Select
ActiveSheet.Range("A:AJ").AutoFilter Field:=25, Criteria1:= _
"<>*testing*", Operator:=xlAnd
varList = Sheets("checks completed").Range("A1:A" & UsdRws).Value
For lngCounter = LBound(varList) To UBound(varList)
With ActiveSheet.Range("d:d")
Set rngFound = .Find( _
What:=varList(lngCounter, 1), _
Lookat:=xlWhole, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=True _
)
If Not rngFound Is Nothing Then
If rngToDelete Is Nothing Then
Set rngToDelete = rngFound
Else
Set rngToDelete = Application.Union(rngToDelete, rngFound)
End If
strFirstAddress = rngFound.Address
Set rngFound = .FindNext(After:=rngFound)
Do Until rngFound.Address = strFirstAddress
Set rngToDelete = Application.Union(rngToDelete, rngFound)
Set rngFound = .FindNext(After:=rngFound)
Loop
End If
End With
Next lngCounter
If Not rngToDelete Is Nothing Then rngToDelete.EntireRow.Delete
Range("a1").Select
Sheets("instructions").Select
End Sub
thanks for any help.