Link to home
Start Free TrialLog in
Avatar of bsharath
bsharathFlag for India

asked on

Excel sheet find for a text and delete the whole row

Hi,

I want to find for a text and delete the whole row in the excel sheet.

Regards
Sharath
Avatar of mandelia
mandelia
Flag of India image



the column number you are searching your text is in 1


sub delete()
dim i as long
for i = 1 to 65000
if  cells(i,1) = "whatever you want"
rows(i).select
Selection.Delete Shift:=xlUp
i = i - 1
end if
next i
end sub
Avatar of bsharath

ASKER

I get this error.
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Syntax error
---------------------------
OK   Help  
---------------------------

if  cells(i,1) = "whatever you want"
use cell(i,1).value
Can you post the whole edited macro
sub delete()
dim i as long
for i = 1 to 65000
if  cells(i,1).value = "whatever you want"
rows(i).select
Selection.Delete Shift:=xlUp
i = i - 1
end if
next i
end sub
This still gives a compile error.

if  cells(i,1).value = "whatever you want"
ok got it try this
sub delete()
dim i as long
for i = 1 to 65000
if  Sheet1.cells(i,1).value = "whatever you want"
rows(i).select
Selection.Delete Shift:=xlUp
i = i - 1
end if
next i
end sub


   

ok got it try this
sorry
sub delete()
dim i as long
for i = 1 to 65000
if  Sheet1.cells(i,1).value = "whatever you want"
Sheet1.rows(i).select
Selection.Delete Shift:=xlUp
i = i - 1
end if
next i
end sub
Still get this error.

---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Syntax error
---------------------------
OK   Help  
---------------------------
ok got it try this
sorry
sorry
sub delete()
dim i as long
for i = 1 to 65000
if  Sheet1.cells(i,1).value = "whatever you want" then
Sheet1.rows(i).select
Selection.Delete Shift:=xlUp
i = i - 1
end if
next i
end sub

I have done some modification pls check
Sub del()
Dim i As Long
x = Application.InputBox("Enter Value")
For i = 1 To 65000
If Sheet1.Cells(i, 1).Value = Conversion.CStr(x) Then
Sheet1.Rows(i).Select
Selection.delete Shift:=xlUp
i = i - 1
End If
Next i
End Sub
End If
Next i
End Sub
Hitesh

No error and i dont get a box to enter

Patel i get this.
---------------------------
Microsoft Visual Basic
---------------------------
Compile error:

Only comments may appear after End Sub, End Function, or End Property
---------------------------
OK   Help  
---------------------------
ok check this
Sub del()
Dim i As Long
x = InputBox("Enter Value")
For i = 1 To 65000
If Sheet1.Cells(i, 1).Value = Str(x) Then
Sheet1.Rows(i).Select
Selection.delete Shift:=xlUp
i = i - 1
End If
Next i
End Sub
Sub del()
Dim i As Long
x = Application.InputBox("Enter Value")
For i = 1 To 65000
If Sheet1.Cells(i, 1).Value = Conversion.CStr(x) Then
Sheet1.Rows(i).Select
Selection.delete Shift:=xlUp
i = i - 1
End If
Next i
End Sub
patel.
I get no errors nor results.
I have this in the excel
Sharath   Reddy
ramesh  Sasi

When i enter sharath there is no changes.
Ok got it.I think this works only for numbers....
Can it even search text and perform the same.
ok try this
Sub del()
Dim i As Long
x = InputBox("Enter Value")
For i = 1 To 65000
If UCase(Sheet1.Cells(i, 1).Value) = UCase(Str(x)) Then
Sheet1.Rows(i).Select
Selection.delete Shift:=xlUp
i = i - 1
End If
Next i
End Sub


   

Some issue in the macro.

The excel restarts and goes to recovery mode.
ok try this
Sub del()
Dim i As Long
x = InputBox("Enter Value")
For i = 1 To 65000
If UCase(Sheet1.Cells(i, 1).Value) = UCase(Str(x)) Then
Sheet1.Rows(i).Select
Selection.delete Shift:=xlUp
End If
Next i
End Sub
The same error. Excel restarting
ok try this
Sub del()
Dim i As Long
x = InputBox("Enter Value")
For i = 1 To Sheet1.UsedRange.Rows.Count
If UCase(Sheet1.Cells(i, 1).Value) = UCase(Str(x)) Then
      Sheet1.Rows(i).Select
      Selection.delete Shift:=xlUp
End If
Next i
End Sub

did this solve the problem?
Same problem Excel restarting
i dont understand why, just delete everything and paste the above lines again
No same error.Any other way of doing this.
ok try this
Sub deletesearch()
Dim i As Long
x = InputBox("Enter Value")
For i = 1 To Sheet1.UsedRange.Rows.Count
    If UCase(Sheet1.Cells(i, 1).Value) = UCase(Str(x)) Then
        Sheet1.Rows(i).Delete
    End If
Next
End Sub
Same i get an error and the excel restarts
can you upload the file?
ok try this
Sub deletesearch()
Dim i As Long, x As String
x = InputBox("Enter Value")
For i = 1 To Sheet1.UsedRange.Rows.Count
    If UCase(Sheet1.Cells(i, 1).Value) = UCase(x) Then
        Sheet1.Rows(i).Delete
    End If
Next
End Sub
Ok this is fine.But when the data is in some other colum it does not delete
ASKER CERTIFIED SOLUTION
Avatar of Hitesh Manglani
Hitesh Manglani
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial