PC Review


Reply
Thread Tools Rate Thread

delete all rows not beginning with

 
 
SITCFanTN
Guest
Posts: n/a
 
      11th Nov 2009
I need to write some code that would delete all rows in the open document
where AAAF800 or AAAF900 or AAA1000 are not in column A. I have searched the
site and am not able to find anything that would help me with this. Any
suggestions are greatly appreciated. Thank you,
 
Reply With Quote
 
 
 
 
JLGWhiz
Guest
Posts: n/a
 
      11th Nov 2009
You can try this. It assumes row 1 as header row.

Sub deleRwCpy()
Dim myRng As Range, sh As Worksheet
Set sh = ActiveSheet
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
For i = lr To 2 Step -1
If sh.Cells(i, 1) <> "AAAF800" And sh.Cells(i, 1) <> _
"AAAF9000" And sh.Cells(i, 1) <> AAA1000 Then
Cells(i, 1).EntireRow.Delete
End If
Next
End Sub


"SITCFanTN" <(E-Mail Removed)> wrote in message
news:FA346CC8-C6BE-48C6-B8A4-(E-Mail Removed)...
>I need to write some code that would delete all rows in the open document
> where AAAF800 or AAAF900 or AAA1000 are not in column A. I have searched
> the
> site and am not able to find anything that would help me with this. Any
> suggestions are greatly appreciated. Thank you,



 
Reply With Quote
 
Lars-ke Aspelin
Guest
Posts: n/a
 
      11th Nov 2009
On Wed, 11 Nov 2009 11:44:01 -0800, SITCFanTN
<(E-Mail Removed)> wrote:

>I need to write some code that would delete all rows in the open document
>where AAAF800 or AAAF900 or AAA1000 are not in column A. I have searched the
>site and am not able to find anything that would help me with this. Any
>suggestions are greatly appreciated. Thank you,



Try this macro:

Sub delete_rows()
For r = Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1
If Not (Cells(r, "A") = "AAAF800" Or _
Cells(r, "A") = "AAAF900" Or _
Cells(r, "A") = "AAA1000") Then
Rows(r).Delete
End If
Next r
End Sub

Hope this helps / Lars-ke
 
Reply With Quote
 
B Lynn B
Guest
Posts: n/a
 
      11th Nov 2009
You don't really need code to accomplish this. Just apply a filter to the
range, and use the column A filter dropdown selector to uncheck those three
items. Then delete the remaining rows.

"SITCFanTN" wrote:

> I need to write some code that would delete all rows in the open document
> where AAAF800 or AAAF900 or AAA1000 are not in column A. I have searched the
> site and am not able to find anything that would help me with this. Any
> suggestions are greatly appreciated. Thank you,

 
Reply With Quote
 
Gary''s Student
Guest
Posts: n/a
 
      11th Nov 2009
Here is one approach:

Sub RowKiller()
Dim r As Range, rKill As Range
Set r = Intersect(ActiveSheet.UsedRange, Range("A:A"))
Set rKill = Nothing
For Each rr In r
v = rr.Value
If v = "AAAF800" Or v = "AAAF900" Or v = "AAAF1000" Then
Else
If rKill Is Nothing Then
Set rKill = rr
Else
Set rKill = Union(rKill, rr)
End If
End If
Next
If rKill Is Nothing Then
Else
rKill.EntireRow.Delete
End If
End Sub

We build a set of rows and delete them in one swell foop!
--
Gary''s Student - gsnu200908


"SITCFanTN" wrote:

> I need to write some code that would delete all rows in the open document
> where AAAF800 or AAAF900 or AAA1000 are not in column A. I have searched the
> site and am not able to find anything that would help me with this. Any
> suggestions are greatly appreciated. Thank you,

 
Reply With Quote
 
John_John
Guest
Posts: n/a
 
      11th Nov 2009
Another diferent approach:

Sub DeleteRows()
Dim i As Integer
Dim rngFound As Range
Dim rngAllRows As Range

On Error Resume Next
Set rngAllRows = Range("A:A")
For i = 800 To 1000 Step 100
Set rngFound = Range("A:A").Find("AAAF" & i)
If Not rngFound Is Nothing Then
Set rngAllRows = rngAllRows.ColumnDifferences(rngFound)
End If
Set rngFound = Nothing
Next i
rngAllRows.EntireRow.Delete
End Sub

Ο χρήστης "Lars-Åke Aspelin" *γγραψε:

> On Wed, 11 Nov 2009 11:44:01 -0800, SITCFanTN
> <(E-Mail Removed)> wrote:
>
> >I need to write some code that would delete all rows in the open document
> >where AAAF800 or AAAF900 or AAA1000 are not in column A. I have searched the
> >site and am not able to find anything that would help me with this. Any
> >suggestions are greatly appreciated. Thank you,

>
>
> Try this macro:
>
> Sub delete_rows()
> For r = Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1
> If Not (Cells(r, "A") = "AAAF800" Or _
> Cells(r, "A") = "AAAF900" Or _
> Cells(r, "A") = "AAA1000") Then
> Rows(r).Delete
> End If
> Next r
> End Sub
>
> Hope this helps / Lars-Åke
> .
>

 
Reply With Quote
 
Lars-ke Aspelin
Guest
Posts: n/a
 
      12th Nov 2009
Note that it is "AAA1000" and not "AAAF1000"

Lars-ke

On Wed, 11 Nov 2009 15:53:01 -0800, John_John
<(E-Mail Removed)> wrote:

>Another diferent approach:
>
>Sub DeleteRows()
> Dim i As Integer
> Dim rngFound As Range
> Dim rngAllRows As Range
>
> On Error Resume Next
> Set rngAllRows = Range("A:A")
> For i = 800 To 1000 Step 100
> Set rngFound = Range("A:A").Find("AAAF" & i)
> If Not rngFound Is Nothing Then
> Set rngAllRows = rngAllRows.ColumnDifferences(rngFound)
> End If
> Set rngFound = Nothing
> Next i
> rngAllRows.EntireRow.Delete
>End Sub
>
>? ??????? "Lars-ke Aspelin" ???????:
>
>> On Wed, 11 Nov 2009 11:44:01 -0800, SITCFanTN
>> <(E-Mail Removed)> wrote:
>>
>> >I need to write some code that would delete all rows in the open document
>> >where AAAF800 or AAAF900 or AAA1000 are not in column A. I have searched the
>> >site and am not able to find anything that would help me with this. Any
>> >suggestions are greatly appreciated. Thank you,

>>
>>
>> Try this macro:
>>
>> Sub delete_rows()
>> For r = Cells.SpecialCells(xlCellTypeLastCell).Row To 1 Step -1
>> If Not (Cells(r, "A") = "AAAF800" Or _
>> Cells(r, "A") = "AAAF900" Or _
>> Cells(r, "A") = "AAA1000") Then
>> Rows(r).Delete
>> End If
>> Next r
>> End Sub
>>
>> Hope this helps / Lars-ke
>> .
>>


 
Reply With Quote
 
John_John
Guest
Posts: n/a
 
      12th Nov 2009
Oh! Sorry! It was great my carelessness !
Thnks Lars!
I will try to make amends.

Sub DeleteRows()
Dim i As Integer
Dim rngFound As Range
Dim rngAllRows As Range
Dim astrText() As Variant

On Error Resume Next
astrText = Array("AAAF800", "AAAF900", "AAA1000")
Set rngAllRows = Range("A:A")
For i = LBound(astrText) To UBound(astrText)
Set rngFound = Range("A:A").Find(astrText(i))
If Not rngFound Is Nothing Then
Set rngAllRows = rngAllRows.ColumnDifferences(rngFound)
End If
Set rngFound = Nothing
Next i
rngAllRows.EntireRow.Delete
End Sub




Ο χρήστης "Lars-Åke Aspelin" *γγραψε:

> Note that it is "AAA1000" and not "AAAF1000"
>
> Lars-Åke
>
> On Wed, 11 Nov 2009 15:53:01 -0800, John_John
> <(E-Mail Removed)> wrote:
>
> >Another diferent approach:
> >
> >Sub DeleteRows()
> > Dim i As Integer
> > Dim rngFound As Range
> > Dim rngAllRows As Range
> >
> > On Error Resume Next
> > Set rngAllRows = Range("A:A")
> > For i = 800 To 1000 Step 100
> > Set rngFound = Range("A:A").Find("AAAF" & i)
> > If Not rngFound Is Nothing Then
> > Set rngAllRows = rngAllRows.ColumnDifferences(rngFound)
> > End If
> > Set rngFound = Nothing
> > Next i
> > rngAllRows.EntireRow.Delete
> >End Sub
> >


 
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
RE: How do I set end-of-range to #rows from beginning Shane Devenshire Microsoft Excel Charting 0 27th Jun 2009 08:08 PM
Removing rows with spaces at beginning of cell? shawn Microsoft Excel Discussion 8 9th Mar 2009 03:41 PM
Identifying Beginning and Ending Rows in a Selected Range JR_06062005 Microsoft Excel Programming 2 28th Nov 2007 02:31 PM
algorithm to add 20 rows at half way point & at beginning =?Utf-8?B?SmFuaXM=?= Microsoft Excel Programming 1 3rd Oct 2007 10:56 PM
On printing out a set of rows and columns at the beginning of every sheet. Don J Microsoft Excel Discussion 7 9th Apr 2007 03:02 AM


Features
 

Advertising
 

Newsgroups
 


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