View Single Post
  #10   Report Post  
Posted to microsoft.public.excel.worksheet.functions
Conan Kelly Conan Kelly is offline
external usenet poster
 
Posts: 419
Default What is wrong with this Macro?

Jeannie,

I just saw your resonse to Gord Dibben's reply.

Use something like this for your "IF" statement:

If Cells(i, "I") = 0 AND _
(Cells(i, "J") = "LOA" Or _
Cells(i, "J") = "Termed" Or _
Cells(i, "J") = "Duplicate") Then

Hopefully that should work for you.

HTH,

Conan






"Conan Kelly" wrote in message
...
Jeannie,

You want rows deleted ONLY when there is a 0 (zero) in column I? What
about column J being LOA, Termed, or Duplicate? Is zero stored as text or
as a number?

For just 0 as a number:


Sub DeleteLOATermedDupRecords()
Application.Calculation = xlCalculationManual
For i = 1 To 12000
If Cells(i, "I") = 0 Then
Rows(i & ":" & i).Select
Selection.Delete Shift:=xlUp
i = i - 1
End If
Next i
Application.Calculation = xlCalculationAutomatic
End Sub



For just 0 as text:


Sub DeleteLOATermedDupRecords()
Application.Calculation = xlCalculationManual
For i = 1 To 12000
If Cells(i, "I") = "0" Then '<--Quotes around the zero
Rows(i & ":" & i).Select
Selection.Delete Shift:=xlUp
i = i - 1
End If
Next i
Application.Calculation = xlCalculationAutomatic
End Sub



If you want to include column J criteria, then you'll have to add your
previous statements with the correct combination of OR's & AND's,
depending on your requierments.

But Don Guillett's solution is more efficent. His suggestion for working
from the bottom up when deleting cells is right on, although I did see
that you compensated for the deleted row with "i = i - 1" inside the loop.
Also he suggests that you do not select the row you want to first, just
delete it without selecting it. That is another good suggestion.
Remember, you don't need to select any cells to make almost any changes
you can think of. Almost everything (if not everything) can be done
without selecting.

So, to edit his code to accomplish what I did above:


Application.Calculation = xlCalculationManual
mc="J"
For i = cells(rows.count,mc).end(xlup).row to 1 step-1
If Cells(i,"I") = 0 Then 'for zero stored as a number (comment
for 0 as text)
'If Cells(i,"I") = 0 Then 'uncomment this line for zero as text
Rows(i).delete
end if
Next i
Application.Calculation = xlCalculationAutomatic




HTH,

Conan




"jeannie v" wrote in message
...
Hi Conan:

Whoa.....thank you...it works just as it's suppose to with your
recommendation......I am truly grateful....I will remember that for
future
applications....

I have another favor to ask....If I want this macro to just delete the
rows
that have a 0 in Column I, how can I revise the macro to do that?

Any help would be greatly appreciated!
--
jeannie v


"Conan Kelly" wrote:

Jeannie,

Is automatic calculation turned on? Is it recalculating after each row
is
deleted (watch the status bar in the bottom left corner of the XL
window...It will say something like "Calculating" and give a
percentage)?
Does this workbook/worksheet take some time to recalculate?

If that is your issue, then you can turn AutoCalc off by putting this as
one
of the first lines in your macro:

Application.Calculation = xlCalculationManual

.... and then turn it back on by putting this as the last line in the
macro:

Application.Calculation = xlCalculationAutomatic

HTH,

Conan

"jeannie v" wrote in message
...
Hi Experts:

I have used this macro before and it worked perfectly...however, now
when
it
searches and deletes the rows that I want it to, it takes forever to
go
through the document....It used to go through very fast and deleted
the
rows,
but now it deletes one row at a time very slowly....I have about 10000
records for it to go through and delete the records that are in the
macro
and
it takes a long time to complete...What might be wrong with this
Macro?

Sub DeleteLOATermedDupRecords()
'
' DeleteLOATermedDupRecords Macro
' Macro recorded 2/17/2008 by Jeannie Vincovich
'
For i = 1 To 12000
If Cells(i, "J") = "LOA" Or Cells(i, "J") = "Termed" Or _
Cells(i, "J") = "Duplicate" Then
Rows(i & ":" & i).Select
Selection.Delete Shift:=xlUp
i = i - 1
End If
Next i

End Sub


Any help you can provide would be greatly appreciated.
--
jeannie v