Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default delete all rows but rows with value =

hi,
i'm trying to modify the following code from Ron de Bruns Excel page.
i need the macro to delete all rows that do not equal "abc" in column
C; instead of deleting all rows with "abc" as it currently does. how
do i modify this? If i use "<" by Criteria1 i get an error. also,
would it be possible to create a prompt for this 'do not delete' value?


Sub Delete_with_Autofilter()
Dim DeleteValue As String
Dim rng As Range

DeleteValue = "abc"

With ActiveSheet
.Range("A1:C40000").AutoFilter Field:=3, Criteria1:=DeleteValue
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete

End With
.AutoFilterMode = False
End With
End Sub

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 644
Default delete all rows but rows with value =

Sub Delete_with_Autofilter()
Dim DeleteValue As String
Dim rng As Range


DeleteValue = InputBox("Please Enter Data to Filter")


With ActiveSheet
.Range("A1:C40000").AutoFilter Field:=3, Criteria1:="<" &
DeleteValue
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete


End With
.AutoFilterMode = False
End With
End Sub

Give that a shot and let me know if it works.

Charles Chickering

yoram wrote:
hi,
i'm trying to modify the following code from Ron de Bruns Excel page.
i need the macro to delete all rows that do not equal "abc" in column
C; instead of deleting all rows with "abc" as it currently does. how
do i modify this? If i use "<" by Criteria1 i get an error. also,
would it be possible to create a prompt for this 'do not delete' value?


Sub Delete_with_Autofilter()
Dim DeleteValue As String
Dim rng As Range

DeleteValue = "abc"

With ActiveSheet
.Range("A1:C40000").AutoFilter Field:=3, Criteria1:=DeleteValue
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete

End With
.AutoFilterMode = False
End With
End Sub


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 22
Default delete all rows but rows with value =

That works great. Thanks a bunch!!

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
Hpw do I delete multiple empty rows found between filled rows? Bill Excel Worksheet Functions 2 November 15th 09 07:12 PM
How to Delete empty rows in excel in b/w rows with values Dennis Excel Worksheet Functions 3 August 28th 07 04:15 PM
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows Scott Excel Worksheet Functions 0 December 13th 06 01:25 AM
Delete rows with numeric values, leave rows with text GSpline Excel Programming 5 October 11th 05 12:44 AM
delete empty rows between rows with text Paulo Baptista Excel Discussion (Misc queries) 2 February 28th 05 03:41 PM


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