Remove rows

ron.bo

Board Regular
Joined
Mar 15, 2011
Messages
129
Office Version
  1. 2007
Platform
  1. Windows
I have the following code and am using excel 2003;

Sub RemoveRowByWord()
Dim myRng As Range
Dim FoundCell As Range
Dim wks As Worksheet
Dim myStrings As Variant
Dim iCtr As Long

myStrings = Array("2", "4")
'myStrings = Sheets("Sheet2").Range("A1:A3")
Set wks = ActiveSheet

With wks
Set myRng = .Range("a1:a" & .Rows.Count)
End With

For iCtr = LBound(myStrings) To UBound(myStrings)
Do
With myRng
Set FoundCell = .Cells.Find(What:=myStrings(iCtr), _
after:=.Cells(.Cells.Count), _
LookIn:=xlValues, _
LookAt:=xlWhole, _
SearchOrder:=xlByRows, _
searchdirection:=xlNext, _
MatchCase:=False)

If FoundCell Is Nothing Then
Exit Do
Else
FoundCell.EntireRow.Delete
End If
End With
Loop
Next iCtr
End Sub

"On "sheet 1" "column A" I have 1,2,3,4... 25 in A1 to A25. On "sheet 2" "column A" I have 2,4,6,8,10... 24 in A1 to A12.

The above code works if I put the number/word into the array, but I do not want to put it into the code each time I add something to be deleted. Instead, I want to use a list on sheet 2 of rows to be deleted that I can continually add to.

I found a message from Ron de Bruin that stated "myStrings = Sheets("Sheet2").Range("A1:A250") could replace the array. However, that does not work for me.

So I am looking for the code that will delete rows on sheet 1 that have a value/string that is listed on sheet 2 row a.

Thanks for any help

Ronbo
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Code:
myStrings = Application.Transpose(Sheets("Sheet2").Range("A1:A3").Value)

or

Code:
myStrings = Application.Transpose([Sheet2!A1:A3].Value)

Please add code tags to your code when you paste it on the forum. Thanks.
 
Upvote 0
Perfect! Thank-you.

Ron.bo

P.S. I am somewhat new to this BB. Is there a way to mark a post as answered?
 
Upvote 0
Perfect! Thank-you.

Ron.bo

P.S. I am somewhat new to this BB. Is there a way to mark a post as answered?

No, but you do not need to do it. A message like the above suffices and is gratefully acknowledged.
 
Upvote 0

Forum statistics

Threads
1,224,570
Messages
6,179,611
Members
452,931
Latest member
The Monk

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