G
Gordon
Hi...
Thanks to those who have got the code below to where it
is.
This code launches the input box and will then go onto
delete all rows where the value in the input box was
found. Great!
However, if I don't enter a value and/or cancel the input
box the code below deletes every row where 0 occours.
How can I avoid this?
Public Sub remove()
Worksheets("Sheet1").Activate
Dim lastrow As Long
Dim lastcol As Long
Dim sString As String
sString = InputBox("ENETR YOUR VALUE: ANY ROW WHERE
THIS VALUE IS FOUND WILL BE DELETED")
lastrow = ActiveSheet.UsedRange.Rows.Count
lastcol = ActiveSheet.UsedRange.Columns.Count
Application.ScreenUpdating = False
Dim ir As Long, ic As Long, rd As Long
For ir = lastrow To 1 Step -1
For ic = lastcol To 1 Step -1
Cells(ir, ic).Activate
If UCase(Cells(ir, ic).Value) = UCase(sString) Then
Rows(ir).Delete shift:=xlUp
ir = ir - 1
ic = lastcol + 1
rd = rd + 1
End If
Next ic
Next ir
Application.ScreenUpdating = True
MsgBox "You have deleted: " & rd & " rows"
End Sub
Thanks in advance...
Gordon.
Thanks to those who have got the code below to where it
is.
This code launches the input box and will then go onto
delete all rows where the value in the input box was
found. Great!
However, if I don't enter a value and/or cancel the input
box the code below deletes every row where 0 occours.
How can I avoid this?
Public Sub remove()
Worksheets("Sheet1").Activate
Dim lastrow As Long
Dim lastcol As Long
Dim sString As String
sString = InputBox("ENETR YOUR VALUE: ANY ROW WHERE
THIS VALUE IS FOUND WILL BE DELETED")
lastrow = ActiveSheet.UsedRange.Rows.Count
lastcol = ActiveSheet.UsedRange.Columns.Count
Application.ScreenUpdating = False
Dim ir As Long, ic As Long, rd As Long
For ir = lastrow To 1 Step -1
For ic = lastcol To 1 Step -1
Cells(ir, ic).Activate
If UCase(Cells(ir, ic).Value) = UCase(sString) Then
Rows(ir).Delete shift:=xlUp
ir = ir - 1
ic = lastcol + 1
rd = rd + 1
End If
Next ic
Next ir
Application.ScreenUpdating = True
MsgBox "You have deleted: " & rd & " rows"
End Sub
Thanks in advance...
Gordon.