Godders199
Active Member
- Joined
- Mar 2, 2017
- Messages
- 313
- Office Version
- 2013
Hello, I have the following code , which identifies rows to delete from a list on a seperate sheet. the only issue is i need to remember to change varList = Range("deselect!A1:A10").Value if the list has more than 10 entries.
I have tried adding a last row count into the VBA, but cannot get anything to work. SO effectively i am just looking for the code to replace varList = Range("deselect!A1:A10").Value with A1 and lastrow.
Sub remove()
Dim rngFound As Range, rngToDelete As Range
Dim strFirstAddress As String
Dim varList As Variant
Dim lngCounter As Long
Application.ScreenUpdating = False
Sheets("submissions").Select
varList = Range("deselect!A1:A10").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
Application.ScreenUpdating = True
End Sub
Any help would be appreciated
I have tried adding a last row count into the VBA, but cannot get anything to work. SO effectively i am just looking for the code to replace varList = Range("deselect!A1:A10").Value with A1 and lastrow.
Sub remove()
Dim rngFound As Range, rngToDelete As Range
Dim strFirstAddress As String
Dim varList As Variant
Dim lngCounter As Long
Application.ScreenUpdating = False
Sheets("submissions").Select
varList = Range("deselect!A1:A10").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
Application.ScreenUpdating = True
End Sub
Any help would be appreciated