thamestowers
New Member
- Joined
- Jun 8, 2014
- Messages
- 23
Good day everyone!
I have this code, that for some reason it is not being performed entirely over the used range
E.g. There are 30 rows, ONLY from project "B" if I say in the box that I want the Project "A" it does not delete all of the Project B rows, just few...
So how do I get the code to go through the used range?
Any ideas would be really appreciated!
Thank you in advance!!
Here is the code:
Sub testforupdate()
Dim inputproj As String
Dim r As Range
Dim i As Integer
lastcell = Sheets("Data").UsedRange.End(xlUp).Row
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
inputproj = Application.InputBox("Please enter the Project Name:", "Project selection")
Set r = Sheets("Data").Range("BL2:BL500")
For i = 0 To lastcell
For Each r In Intersect(Range("BL2:BL500"), ActiveSheet.UsedRange)
If r.Value <> inputproj Then
r.EntireRow.delete
End If
Next r
Next i
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub
I have this code, that for some reason it is not being performed entirely over the used range
E.g. There are 30 rows, ONLY from project "B" if I say in the box that I want the Project "A" it does not delete all of the Project B rows, just few...
So how do I get the code to go through the used range?
Any ideas would be really appreciated!
Thank you in advance!!
Here is the code:
Sub testforupdate()
Dim inputproj As String
Dim r As Range
Dim i As Integer
lastcell = Sheets("Data").UsedRange.End(xlUp).Row
With Application
.ScreenUpdating = False
.EnableEvents = False
End With
inputproj = Application.InputBox("Please enter the Project Name:", "Project selection")
Set r = Sheets("Data").Range("BL2:BL500")
For i = 0 To lastcell
For Each r In Intersect(Range("BL2:BL500"), ActiveSheet.UsedRange)
If r.Value <> inputproj Then
r.EntireRow.delete
End If
Next r
Next i
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
End Sub