Hey everyone
I have a problem deleting rows based on a condition, i didn't know how to use offset method.
i'm using a table like this one :
A B C
1 Main design1 FFR0
2 Extra design2 FFR0
3 Main design3 FFR0
4 Extra design4 FFR0
.
.
n Main designn FFR0
I want to delete entire row if "FFR0" in column C exists in a row beginning by "EXTRA" (column A)
thanks in advance for your help
regards
Last edited by mehdoush; 05-18-2009 at 10:26 AM.
Hi,
Code:Sub Macro1() Dim rcell As Range For Each rcell In Range("A:A") If Left(rcell.Value, 5) = "Extra" And Left(rcell.Offset(0, 2).Value, 4) = "FFR0" Then rcell.EntireRow.Delete Next rcell End Sub
Sarcasm - because beating the **** out of someone is illegal.
thanks sweep, i'll try it![]()
well it didn't work properly, i think it's because the range (range("a:a"))
i tried to use "intersect" method to define the range, but it didn't work either
any help plz ??
It was fine with the example data you posted.
How did it not work?
There's no need to evaluate the entire column A, and if you don't start at the bottom and work UP, you'll end up skipping rows. My suggestion:
Code:Sub DeleteRows() Dim i As Long, LastRow As Long LastRow = Range("A" & Rows.Count).End(xlUp).Row For i = LastRow To 1 Step -1 If LCase(Cells(i, "A").Value) Like "extra*" And _ UCase(Cells(i, "C").Value) Like "FFR0*" Then _ Rows(i).EntireRow.Delete Next i End Sub
Last edited by JBeaucaire; 05-13-2009 at 11:44 AM. Reason: Added the wildcard onto FFR0*
_________________
Microsoft MVP 2010 - Excel
Visit: Jerry Beaucaire's Excel Files & Macros
If you've been given good help, use theicon below to give reputation feedback, it is appreciated.
Always put your code between code tags. [CODE] your code here [/CODE]
“None of us is as good as all of us” - Ray Kroc
“Actually, I *am* a rocket scientist.” - JB (little ones count!)
thank you so much, it works properly![]()
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks