Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default Delete all rows except

Was given this code, but doesnt work. It deletes everything.
The data on the worksheet was imported - i think this has something to
do with the reason it doesnt work (or filter) properly.

Sub DeleteRows()


Dim LastRow As Long
Dim rw As Long


Application.ScreenUpdating = False


LastRow = Cells(Rows.Count, "B").End(xlUp).Row


For rw = LastRow To 2 Step -1
If Cells(rw, "B").Value < "Apples" Or Cells(rw, "B").Value
<
"Oranges" Then
Rows(rw).Delete Shift:=xlUp
End If
Next rw


Application.ScreenUpdating = True


End Sub


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 62
Default Delete all rows except

Hi

If a cell is equal to "Apples" then it is not equal to "Oranges"
== the test with "Apples" return False
== the test with "Oranges" return True
False OR True return True

If a cell is equal to "Oranges" then it is not equal to "Apples"
== the test with "Apples" returns True
== the test with "Oranges" returns False
True OR False return True

If a cell is not equal to "Oranges" and is not equal to "Apples"
== the test with "Apples" returns True
== the test with "Oranges" returns True
True OR True returns True

Your formula returns always TRUE

? try to replace OR with AND




"J.W. Aldridge" a écrit dans le message de
groupe de discussion :
...
Was given this code, but doesnt work. It deletes everything.
The data on the worksheet was imported - i think this has something to
do with the reason it doesnt work (or filter) properly.

Sub DeleteRows()


Dim LastRow As Long
Dim rw As Long


Application.ScreenUpdating = False


LastRow = Cells(Rows.Count, "B").End(xlUp).Row


For rw = LastRow To 2 Step -1
If Cells(rw, "B").Value < "Apples" Or Cells(rw, "B").Value
<
"Oranges" Then
Rows(rw).Delete Shift:=xlUp
End If
Next rw


Application.ScreenUpdating = True


End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default Delete all rows except

you were SO right.

Thanx a million..... It works now!

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
Delete & Merge Columns,Delete Rows with filter, etc traderindia Excel Programming 1 July 16th 09 08:17 PM
Delete Rows if any cell in Column H is blank but do not Delete Fir manfareed Excel Programming 4 September 28th 07 05:20 PM
Copy pasting Rows, but need to Delete any Shapes/Pictures that are within copied rows Corey Excel Programming 2 August 1st 07 02:02 AM
How to delete rows when List toolbar's "delete" isnt highlighted? Linda Excel Worksheet Functions 1 May 26th 05 08:39 PM
Delete every 3rd row, then delete rows 2-7, move info f/every 2nd row up one to the end and delete the row below Annette[_4_] Excel Programming 2 September 21st 04 02:40 PM


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