Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default modifications on the code

Hi, Group:

I need your help to modify my code. Here is what I expect:

In Column A under sheet1 with unknown rows, I always want to keep the
first 3 rows. For the rest other than the first 3 rows, I need a maco
to delete any rows if the cell value is NONE of "Apple", "Orange", or
"Banana".

Here is my code:

Sub DeleteRows()

Dim RangeColumnA As Range
Dim j As Range


With Worksheets("Sheet1")
Set RangeColumnA = .Range("A4", .Range("A" & Rows.Count).End(xlUp))
End With

Application.ScreenUpdating = False

For Each j In RangeColumnA
If NOT j.Value = "Apple" Or j.Value = "Orange" or j.Value =
"Banana" Then
j.EntireRow.Delete
End If
Next j

Application.ScreenUpdating = True

End Sub

Please advise!

George

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,202
Default modifications on the code

In just looking at your code (without actually testing it), this line looks
wrong for what you want to do...

If NOT j.Value = "Apple" Or j.Value = "Orange" or
j.Value = "Banana" Then


I think you need parentheses around all of the tests so that the NOT
operator applies to the group...

If NOT (j.Value = "Apple" Or j.Value = "Orange" or j.Value = "Banana") Then

Rick


"George" wrote in message
ps.com...
Hi, Group:

I need your help to modify my code. Here is what I expect:

In Column A under sheet1 with unknown rows, I always want to keep the
first 3 rows. For the rest other than the first 3 rows, I need a maco
to delete any rows if the cell value is NONE of "Apple", "Orange", or
"Banana".

Here is my code:

Sub DeleteRows()

Dim RangeColumnA As Range
Dim j As Range


With Worksheets("Sheet1")
Set RangeColumnA = .Range("A4", .Range("A" & Rows.Count).End(xlUp))
End With

Application.ScreenUpdating = False

For Each j In RangeColumnA
If NOT j.Value = "Apple" Or j.Value = "Orange" or j.Value =
"Banana" Then
j.EntireRow.Delete
End If
Next j

Application.ScreenUpdating = True

End Sub

Please advise!

George


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default modifications on the code

Hi, Rick:

You are right. Thanks.

However, there is one more problem: It looks like that the For
statement is not working properly. I need to press a macro button a
bunch of times to delete all rows which are not "Apple", "Orange", or
"Banana".

Would you please point out where is the problem?

Thanks again,

George



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,494
Default modifications on the code

if you're deleting rows, you need to start at the bottom of the range and work
your way up.

--


Gary


"George" wrote in message
ups.com...
Hi, Rick:

You are right. Thanks.

However, there is one more problem: It looks like that the For
statement is not working properly. I need to press a macro button a
bunch of times to delete all rows which are not "Apple", "Orange", or
"Banana".

Would you please point out where is the problem?

Thanks again,

George





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
IF Statement Modifications Workbook Excel Worksheet Functions 9 February 19th 09 01:55 PM
turn off excel cell modifications? Fredrated Excel Discussion (Misc queries) 1 February 8th 08 07:22 AM
webbrowser - excel - modifications [email protected] Excel Discussion (Misc queries) 1 January 26th 06 04:31 AM
Disable Border and Other Format Modifications TEAM[_12_] Excel Programming 1 December 8th 05 09:38 PM
Modifications to Permutation Macro Henrik[_2_] Excel Programming 1 October 24th 03 06:53 PM


All times are GMT +1. The time now is 07:46 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"