Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
Zak Zak is offline
external usenet poster
 
Posts: 144
Default Macro deletes seperately

I have the following code to do 3 things, when i ran the macro it deleted
just the one thing, then i pressed run again then it did the other thing! it
seemed i had to press run 3 times before the macro executed everything. cant
the macro do them all at once or with just one click?

thanks alot.

Sub Delete_Rows()

Dim rng As Range, cell As Range, del As Range
Set rng = Intersect(Range("I:I"), ActiveSheet.UsedRange)
For Each cell In rng
If (cell.Text) = "Covansys" _
Or (cell.Text) = "AMS" _
Or (cell.Text) = "Apollo" Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.delete
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
Zak Zak is offline
external usenet poster
 
Posts: 144
Default Macro deletes seperately

Thanks that worked, but i dont understand the logic behind it..and dont
understand why mine had to be clicked on 3 times for it to do all 3 things..?

The code that you gave had two conditions, i want to add more.. up to 10.
how do i do this? if i insert a new line after the first condition to put in
a new 1 it displays error?

please explain how i can have more of the same types of conditions in the
macro. for example, if = microsoft, red tray, isoft (all in column I) then
rows should delete all together.

thanks again.

"Don Guillett" wrote:


Try from the bottom up
sub dr()
mc="I"
for i=cells(rows.count,mc).end(xlup).row to 2 step -1
if cells(i,mc)= "AMS" _
Or cells(i,mc)="Apollo" Then rows(i).delete
next i
end sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Zak" wrote in message
...
I have the following code to do 3 things, when i ran the macro it deleted
just the one thing, then i pressed run again then it did the other thing!
it
seemed i had to press run 3 times before the macro executed everything.
cant
the macro do them all at once or with just one click?

thanks alot.

Sub Delete_Rows()

Dim rng As Range, cell As Range, del As Range
Set rng = Intersect(Range("I:I"), ActiveSheet.UsedRange)
For Each cell In rng
If (cell.Text) = "Covansys" _
Or (cell.Text) = "AMS" _
Or (cell.Text) = "Apollo" Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.delete
End Sub



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Macro deletes seperately

I would have to see the detail and would probably suggest using SELECT CASE.
Send your workbook to my address below, if desired.


Don Guillett
Microsoft MVP Excel
SalesAid Software

"Zak" wrote in message
...
Thanks that worked, but i dont understand the logic behind it..and dont
understand why mine had to be clicked on 3 times for it to do all 3
things..?

The code that you gave had two conditions, i want to add more.. up to 10.
how do i do this? if i insert a new line after the first condition to put
in
a new 1 it displays error?

please explain how i can have more of the same types of conditions in the
macro. for example, if = microsoft, red tray, isoft (all in column I) then
rows should delete all together.

thanks again.

"Don Guillett" wrote:


Try from the bottom up
sub dr()
mc="I"
for i=cells(rows.count,mc).end(xlup).row to 2 step -1
if cells(i,mc)= "AMS" _
Or cells(i,mc)="Apollo" Then rows(i).delete
next i
end sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Zak" wrote in message
...
I have the following code to do 3 things, when i ran the macro it
deleted
just the one thing, then i pressed run again then it did the other
thing!
it
seemed i had to press run 3 times before the macro executed everything.
cant
the macro do them all at once or with just one click?

thanks alot.

Sub Delete_Rows()

Dim rng As Range, cell As Range, del As Range
Set rng = Intersect(Range("I:I"), ActiveSheet.UsedRange)
For Each cell In rng
If (cell.Text) = "Covansys" _
Or (cell.Text) = "AMS" _
Or (cell.Text) = "Apollo" Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.delete
End Sub




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,124
Default Macro deletes seperately

Sub replace() 'Don
lr = Cells(Rows.Count, "b").End(xlUp).Row
For Each c In Range("i1:i" & lr)
Select Case UCase(c)
Case "CAPULA", "ISOFT", "MICROSOFT", "RED TRAY", _
"HEDRA", "SYSTEM C" _
: c.Offset(, 1) = "AP"

Case Else
End Select
Next
End Sub

Sub Replace1() 'Don could use this instead
Dim r As Range
Set r = Range("I1", Range("I65536").End(xlUp))
For Each c In r
If c = "Capula" Then c.Offset(, 1) = "AP"
If c = "iSOFT" Then c.Offset(, 1) = "AP" 'watch spelling or use
ucase(c)=ISOFT
'or this longer version does the same
If c.Value = "Microsoft" Then c.Offset(0, 1).Value = "AP"
If c.Value = "Red Tray" Then c.Offset(0, 1).Value = "AP"
If c.Value = "Hedra" Then c.Offset(0, 1).Value = "AP"
If c.Value = "System C" Then c.Offset(0, 1).Value = "AP"
Next
End Sub

--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Don Guillett" wrote in message
...
I would have to see the detail and would probably suggest using SELECT
CASE. Send your workbook to my address below, if desired.


Don Guillett
Microsoft MVP Excel
SalesAid Software

"Zak" wrote in message
...
Thanks that worked, but i dont understand the logic behind it..and dont
understand why mine had to be clicked on 3 times for it to do all 3
things..?

The code that you gave had two conditions, i want to add more.. up to 10.
how do i do this? if i insert a new line after the first condition to put
in
a new 1 it displays error?

please explain how i can have more of the same types of conditions in the
macro. for example, if = microsoft, red tray, isoft (all in column I)
then
rows should delete all together.

thanks again.

"Don Guillett" wrote:


Try from the bottom up
sub dr()
mc="I"
for i=cells(rows.count,mc).end(xlup).row to 2 step -1
if cells(i,mc)= "AMS" _
Or cells(i,mc)="Apollo" Then rows(i).delete
next i
end sub
--
Don Guillett
Microsoft MVP Excel
SalesAid Software

"Zak" wrote in message
...
I have the following code to do 3 things, when i ran the macro it
deleted
just the one thing, then i pressed run again then it did the other
thing!
it
seemed i had to press run 3 times before the macro executed
everything.
cant
the macro do them all at once or with just one click?

thanks alot.

Sub Delete_Rows()

Dim rng As Range, cell As Range, del As Range
Set rng = Intersect(Range("I:I"), ActiveSheet.UsedRange)
For Each cell In rng
If (cell.Text) = "Covansys" _
Or (cell.Text) = "AMS" _
Or (cell.Text) = "Apollo" Then
If del Is Nothing Then
Set del = cell
Else: Set del = Union(del, cell)
End If
End If
Next cell
On Error Resume Next
del.EntireRow.delete
End Sub





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 deletes row in range, macro then skips the row moved up steven.holloway Excel Discussion (Misc queries) 8 June 11th 08 11:40 AM
Macro that deletes every third row....+ ajjag Excel Discussion (Misc queries) 4 June 27th 06 06:03 PM
Macro that deletes certain rows only supamari0 Excel Programming 7 June 9th 06 04:11 PM
is it possible to change this macro to save each sheet seperately? Martyn Excel Programming 4 May 15th 04 07:04 PM
Macro that adds then deletes Brian McGuire Excel Programming 3 December 8th 03 11:28 PM


All times are GMT +1. The time now is 11:49 PM.

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

About Us

"It's about Microsoft Excel"