Delete upon finding

buntykins

Board Regular
Joined
Apr 11, 2002
Messages
76
How do I do this in VBA? I want it look down column A and if there is an cell with "COMPANY NA" in it, I need it to delete the entire row

How do I do this?

Janie
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
Hiya,

Here's some sample code for you to play with. It may not be the most efficient way of doing what you ask but it does work.
Sub test()

Dim LastRow As Long

LastRow = Range("A65536").End(xlUp).Row

Range("A1").Select

Do While ActiveCell.Row <= LastRow

If ActiveCell.Value = "COMPANY NA" Then

Rows(ActiveCell.Row & ":" & ActiveCell.Row).Delete Shift:=xlUp
LastRow = LastRow - 1
End If
ActiveCell.Offset(1, 0).Select
Loop

End Sub


Regards
AJ
 
Upvote 0
This will delete all the occurences of "Company NA"

Sub Macro1()
On Error Resume Next
Err.Clear
Do While Err.Description<> "Object variable or With block variable not set"
Columns("A:A").Find(What:="COMPANY NA").EntireRow.Delete
Loop
End Sub


_________________
It's never too late to learn something new.

Ricky
This message was edited by Ricky Morris on 2002-05-02 08:49
 
Upvote 0

Forum statistics

Threads
1,214,639
Messages
6,120,679
Members
448,977
Latest member
dbonilla0331

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top