Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Macro/Loop If Statement Help -delete the row with the specific te

I am trying to find all the cells in my worksheet that have "AB" in column
'I' and the AB is highlighted with an interior color = 6 .... then delete the
row .

Here is what I have so far.

FIRSTROW = 1
Do While FIRSTROW 0
FIRSTROW = Application.Match("AB", Range("i:i"), 0)
If Range("a" & FIRSTROW).Interior.ColorIndex = 6 Then
Rows(FIRSTROW & ":" & FIRSTROW).Select
Selection.Delete
End If

'this is the part that is not working. What is happening is that when their
is no match the code bombs so I tried to put an if statement in to change the
firstrow to 0 if their is no match. But the if statement is not working.

If FIRSTROW = Application.Match("AB", Range("i:i"), 0) Is Nothing Then
FIRSTROW = 0
End If
Loop

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Macro/Loop If Statement Help -delete the row with the specific te

Sub Test()
Dim iLastRow As Long
Dim i As Long
Dim j As Long

iLastRow = Cells(Rows.Count, "I").End(xlUp).Row
For i = iLastRow To 1 Step -1
If Cells(i, "I").Value = "AB" And _
Rows(i).Delete
End If
Next i
End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bricktop" wrote in message
...
I am trying to find all the cells in my worksheet that have "AB" in column
'I' and the AB is highlighted with an interior color = 6 .... then delete

the
row .

Here is what I have so far.

FIRSTROW = 1
Do While FIRSTROW 0
FIRSTROW = Application.Match("AB", Range("i:i"), 0)
If Range("a" & FIRSTROW).Interior.ColorIndex = 6 Then
Rows(FIRSTROW & ":" & FIRSTROW).Select
Selection.Delete
End If

'this is the part that is not working. What is happening is that when

their
is no match the code bombs so I tried to put an if statement in to change

the
firstrow to 0 if their is no match. But the if statement is not working.

If FIRSTROW = Application.Match("AB", Range("i:i"), 0) Is Nothing Then
FIRSTROW = 0
End If
Loop



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 265
Default Macro/Loop If Statement Help -delete the row with the specific te

try this:

a=1
while a < numberofrows
If cells(a,numcol).Interior.ColorIndex = 6 and cells(a,numcol)="AB" Then
rows(a).delete
a=a+1
else if
a=a+1
end if
wend

remember to change numcol to the number of the column were your AB's are and
numberofrows to the number of the last row used

"Bricktop" wrote:

I am trying to find all the cells in my worksheet that have "AB" in column
'I' and the AB is highlighted with an interior color = 6 .... then delete the
row .

Here is what I have so far.

FIRSTROW = 1
Do While FIRSTROW 0
FIRSTROW = Application.Match("AB", Range("i:i"), 0)
If Range("a" & FIRSTROW).Interior.ColorIndex = 6 Then
Rows(FIRSTROW & ":" & FIRSTROW).Select
Selection.Delete
End If

'this is the part that is not working. What is happening is that when their
is no match the code bombs so I tried to put an if statement in to change the
firstrow to 0 if their is no match. But the if statement is not working.

If FIRSTROW = Application.Match("AB", Range("i:i"), 0) Is Nothing Then
FIRSTROW = 0
End If
Loop

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Macro/Loop If Statement Help -delete the row with the specifi

Bob - This Worked Fantastic. I didn't know you could use an AND statement
with the if too. Just one more question...please. I have more than one that
has to go thru the loop and I was wondering if I can Combine them. Here is
what I have:
'Remove AB Codes that are ETA Pending

Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "I").End(xlUp).row
For i = iLastRow To 1 Step -1
If Cells(i, "I").Value = "AB" And Cells(i, "I").Interior.ColorIndex
= 6 Then
Rows(i).Delete
End If
Next i

iLastRow = Cells(Rows.Count, "I").End(xlUp).row
For i = iLastRow To 1 Step -1

If Cells(i, "I").Value = "ABPEND" And Cells(i,
"I").Interior.ColorIndex = xlNone Then
Rows(i).Delete
End If
Next i


"Bob Phillips" wrote:

Sub Test()
Dim iLastRow As Long
Dim i As Long
Dim j As Long

iLastRow = Cells(Rows.Count, "I").End(xlUp).Row
For i = iLastRow To 1 Step -1
If Cells(i, "I").Value = "AB" And _
Rows(i).Delete
End If
Next i
End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bricktop" wrote in message
...
I am trying to find all the cells in my worksheet that have "AB" in column
'I' and the AB is highlighted with an interior color = 6 .... then delete

the
row .

Here is what I have so far.

FIRSTROW = 1
Do While FIRSTROW 0
FIRSTROW = Application.Match("AB", Range("i:i"), 0)
If Range("a" & FIRSTROW).Interior.ColorIndex = 6 Then
Rows(FIRSTROW & ":" & FIRSTROW).Select
Selection.Delete
End If

'this is the part that is not working. What is happening is that when

their
is no match the code bombs so I tried to put an if statement in to change

the
firstrow to 0 if their is no match. But the if statement is not working.

If FIRSTROW = Application.Match("AB", Range("i:i"), 0) Is Nothing Then
FIRSTROW = 0
End If
Loop




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default Macro/Loop If Statement Help -delete the row with the specifi

You can have Or as well

'Remove AB Codes that are ETA Pending

Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "I").End(xlUp).row
For i = iLastRow To 1 Step -1
If (Cells(i, "I").Value = "AB" And _
Cells(i, "I").Interior.ColorIndex = 6) Or _
(Cells(i, "I").Value = "ABPEND" And _
Cells(i, "I").Interior.ColorIndex = xlNone) Then
Rows(i).Delete
End If
Next i


--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bricktop" wrote in message
...
Bob - This Worked Fantastic. I didn't know you could use an AND statement
with the if too. Just one more question...please. I have more than one

that
has to go thru the loop and I was wondering if I can Combine them. Here

is
what I have:
'Remove AB Codes that are ETA Pending

Dim iLastRow As Long
Dim i As Long

iLastRow = Cells(Rows.Count, "I").End(xlUp).row
For i = iLastRow To 1 Step -1
If Cells(i, "I").Value = "AB" And Cells(i,

"I").Interior.ColorIndex
= 6 Then
Rows(i).Delete
End If
Next i

iLastRow = Cells(Rows.Count, "I").End(xlUp).row
For i = iLastRow To 1 Step -1

If Cells(i, "I").Value = "ABPEND" And Cells(i,
"I").Interior.ColorIndex = xlNone Then
Rows(i).Delete
End If
Next i


"Bob Phillips" wrote:

Sub Test()
Dim iLastRow As Long
Dim i As Long
Dim j As Long

iLastRow = Cells(Rows.Count, "I").End(xlUp).Row
For i = iLastRow To 1 Step -1
If Cells(i, "I").Value = "AB" And _
Rows(i).Delete
End If
Next i
End Sub

--

HTH

RP
(remove nothere from the email address if mailing direct)


"Bricktop" wrote in message
...
I am trying to find all the cells in my worksheet that have "AB" in

column
'I' and the AB is highlighted with an interior color = 6 .... then

delete
the
row .

Here is what I have so far.

FIRSTROW = 1
Do While FIRSTROW 0
FIRSTROW = Application.Match("AB", Range("i:i"), 0)
If Range("a" & FIRSTROW).Interior.ColorIndex = 6 Then
Rows(FIRSTROW & ":" & FIRSTROW).Select
Selection.Delete
End If

'this is the part that is not working. What is happening is that when

their
is no match the code bombs so I tried to put an if statement in to

change
the
firstrow to 0 if their is no match. But the if statement is not

working.

If FIRSTROW = Application.Match("AB", Range("i:i"), 0) Is Nothing

Then
FIRSTROW = 0
End If
Loop








  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 8
Default Macro/Loop If Statement Help -delete the row with the specific te

I tried the following:
Range("U2:U" & LASTROW).FormulaR1C1 =
"=IF(SEARCH(""pen"",RC[-2])0,2,IF(SEARCH(""can"",RC[-2])0,2,IF(SEARCH(""hol"",RC[-2])0,2,1)))"
and this doesn't work either. Can you not do a multiple search?? I tried
just putting one with both of the if statements and that doesn't work either.
Any other suggestions?


"Bricktop" wrote:

I am trying to find all the cells in my worksheet that have "AB" in column
'I' and the AB is highlighted with an interior color = 6 .... then delete the
row .

Here is what I have so far.

FIRSTROW = 1
Do While FIRSTROW 0
FIRSTROW = Application.Match("AB", Range("i:i"), 0)
If Range("a" & FIRSTROW).Interior.ColorIndex = 6 Then
Rows(FIRSTROW & ":" & FIRSTROW).Select
Selection.Delete
End If

'this is the part that is not working. What is happening is that when their
is no match the code bombs so I tried to put an if statement in to change the
firstrow to 0 if their is no match. But the if statement is not working.

If FIRSTROW = Application.Match("AB", Range("i:i"), 0) Is Nothing Then
FIRSTROW = 0
End If
Loop

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
macro to keep specific name colomns and delete all others myshak Excel Discussion (Misc queries) 0 March 9th 09 11:01 PM
Macro to delete rows containing specific data Slohcin New Users to Excel 2 December 20th 06 11:52 AM
delete row contains specific word in an macro Jean-Francois Excel Discussion (Misc queries) 4 January 11th 05 11:40 PM
Macro to delete specific rows Steve Excel Programming 12 October 1st 04 11:50 PM
Warning Statement to Delete Macro John M[_5_] Excel Programming 2 November 25th 03 04:09 PM


All times are GMT +1. The time now is 08:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"