PC Review


Reply
Thread Tools Rate Thread

Delete all rows except...

 
 
joshman
Guest
Posts: n/a
 
      1st Mar 2010
I receive a weekly report & have been asked to delete all rows except
for two particular rows. Here are the two criteria which are in column
A cells:

AWH98228 and AWL99467

Can anyone offer help?

Thanks
 
Reply With Quote
 
 
 
 
Per Jessen
Guest
Posts: n/a
 
      1st Mar 2010
Try this:

Sub RemoveRows()
With Application
.ScreenUpdating = False
.Calculation = xlCalculationManual
End With

LastRow = Range("A" & Rows.Count).End(xlUp).Row
For r = LastRow To 2 Step -1 'Headings in row 1
If Range("A" & r).Value <> "AWH98228" _
And Range("A" & r).Value <> "AWL99467" Then
Rows(r).Delete
End If
Next
With Application
.ScreenUpdating = True
.Calculation = xlCalculationAutomatic
End With
End Sub

Regards,
Per

"joshman" <(E-Mail Removed)> skrev i meddelelsen
news:8f094e16-d4db-493a-83f7-(E-Mail Removed)...
> I receive a weekly report & have been asked to delete all rows except
> for two particular rows. Here are the two criteria which are in column
> A cells:
>
> AWH98228 and AWL99467
>
> Can anyone offer help?
>
> Thanks


 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      1st Mar 2010
Hi,

If these 'rows' only appear once then it shouldn't be too onerous to do it
manually so I'm assuming there are many instances. This will delete all rows
except those that have either of thos string in column A

Sub Sonic()
Dim R As Range
Dim V As Variant
Dim S As String
Dim CopyRange As Range
Set Sht = Sheets("Sheet1")'change to suit
lastrow = Sht.Cells(Cells.Rows.Count, "A").End(xlUp).Row
S = "AWH98228,AWL99467"
V = Split(S, ",")
For Each R In Sht.Range("A1:A" & lastrow)
If IsError(Application.Match(CStr(R.Value), V, 0)) Then
If CopyRange Is Nothing Then
Set CopyRange = R.EntireRow
Else
Set CopyRange = Union(CopyRange, R.EntireRow)
End If
End If
Next R

If Not CopyRange Is Nothing Then
CopyRange.Delete
End If
End Sub


--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"joshman" wrote:

> I receive a weekly report & have been asked to delete all rows except
> for two particular rows. Here are the two criteria which are in column
> A cells:
>
> AWH98228 and AWL99467
>
> Can anyone offer help?
>
> Thanks
> .
>

 
Reply With Quote
 
J_Knowles
Guest
Posts: n/a
 
      2nd Mar 2010
Use Auto Filter

Select all cells with data (in column A) including AWH98228 and AWL99467
values
Turn On Auto Filter
Click on the filter down arrow button
Select Number Filters - Custom Filters

Displays the Custom Filter Input Box
Show rows where:
does not contain AWH98228
and
does not contain AWL99467

click OK

highlight the rows displayed - right click Delete Row

Turn off Auto Filter

and you are left with AWH98228 and AWL99467 rows

HTH,
--
Data Hog


"joshman" wrote:

> I receive a weekly report & have been asked to delete all rows except
> for two particular rows. Here are the two criteria which are in column
> A cells:
>
> AWH98228 and AWL99467
>
> Can anyone offer help?
>
> Thanks
> .
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Autofil on variable rows, delete extract and show remaining rows 1plane Microsoft Excel Programming 3 17th Nov 2009 10:49 AM
Hpw do I delete multiple empty rows found between filled rows? Bill Microsoft Excel Worksheet Functions 1 15th Nov 2009 12:52 AM
Copy pasting Rows, but need to Delete any Shapes/Pictures that are within copied rows Corey Microsoft Excel Programming 2 1st Aug 2007 02:02 AM
Cut filtered rows, paste into next empty row of new sheet, and delete cut rows Scott Microsoft Excel Worksheet Functions 0 13th Dec 2006 01:25 AM
Delete rows with numeric values, leave rows with text =?Utf-8?B?R1NwbGluZQ==?= Microsoft Excel Programming 5 11th Oct 2005 12:44 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:55 PM.