PC Review


Reply
Thread Tools Rate Thread

delete entire row based on conditional test of column A

 
 
=?Utf-8?B?Z3VpbGxlcm1vLmh0?=
Guest
Posts: n/a
 
      22nd Jan 2007
I have a spreadsheet with various invoice numbers in column A:
For example:
FC110107-002
PB110107-001
LV010707-001

I need a VBA macro that will delete delete an entire row if the LEFT 2
characters of a cell in column A have either: FC, PB, or GR

The default range of my data is usually rows 2 - 2000

I cannot seem to find other snippets of code that work for my needs, so any
help would be appreciated.

 
Reply With Quote
 
 
 
 
Chip Pearson
Guest
Posts: n/a
 
      22nd Jan 2007
Try something like the following:

Sub AAA()

Dim LastRow As Long
Dim FirstRow As Long
Dim RowNdx As Long
Dim WS As Worksheet

FirstRow = 1 '<<< CHANGE AS REQUIRED
Set WS = Worksheets("Sheet1") '<<< CHANGE AS REQUIRED

With WS
LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
For RowNdx = LastRow To FirstRow Step -1
Select Case Left(.Cells(RowNdx, "A").Value, 2)
Case "FC", "PB", "GR"
.Rows(RowNdx).Delete shift:=xlUp
Case Else
' do nothing
End Select
Next RowNdx
End With

End Sub



--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com
(email address is on the web site)

"guillermo.ht" <(E-Mail Removed)> wrote in message
news:273FA7D2-EF9A-425F-BA6A-(E-Mail Removed)...
>I have a spreadsheet with various invoice numbers in column A:
> For example:
> FC110107-002
> PB110107-001
> LV010707-001
>
> I need a VBA macro that will delete delete an entire row if the LEFT 2
> characters of a cell in column A have either: FC, PB, or GR
>
> The default range of my data is usually rows 2 - 2000
>
> I cannot seem to find other snippets of code that work for my needs, so
> any
> help would be appreciated.
>



 
Reply With Quote
 
=?Utf-8?B?Z3VpbGxlcm1vLmh0?=
Guest
Posts: n/a
 
      22nd Jan 2007
Thank you very much. This worked perfectly and has saved me a serious headache.

"Chip Pearson" wrote:

> Try something like the following:
>
> Sub AAA()
>
> Dim LastRow As Long
> Dim FirstRow As Long
> Dim RowNdx As Long
> Dim WS As Worksheet
>
> FirstRow = 1 '<<< CHANGE AS REQUIRED
> Set WS = Worksheets("Sheet1") '<<< CHANGE AS REQUIRED
>
> With WS
> LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row
> For RowNdx = LastRow To FirstRow Step -1
> Select Case Left(.Cells(RowNdx, "A").Value, 2)
> Case "FC", "PB", "GR"
> .Rows(RowNdx).Delete shift:=xlUp
> Case Else
> ' do nothing
> End Select
> Next RowNdx
> End With
>
> End Sub
>
>
>
> --
> Cordially,
> Chip Pearson
> Microsoft MVP - Excel
> Pearson Software Consulting, LLC
> www.cpearson.com
> (email address is on the web site)
>
> "guillermo.ht" <(E-Mail Removed)> wrote in message
> news:273FA7D2-EF9A-425F-BA6A-(E-Mail Removed)...
> >I have a spreadsheet with various invoice numbers in column A:
> > For example:
> > FC110107-002
> > PB110107-001
> > LV010707-001
> >
> > I need a VBA macro that will delete delete an entire row if the LEFT 2
> > characters of a cell in column A have either: FC, PB, or GR
> >
> > The default range of my data is usually rows 2 - 2000
> >
> > I cannot seem to find other snippets of code that work for my needs, so
> > any
> > help would be appreciated.
> >

>
>
>

 
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
HOW CAN I APPLY CONDITIONAL FORMATTING BASED TO AN ENTIRE ROW? =?Utf-8?B?SmFtZXMgTQ==?= Microsoft Excel Programming 7 2nd Sep 2008 04:07 PM
Need a Marco to find and delete an entire column based on text sea Rockpaw Microsoft Excel Programming 1 29th May 2008 08:12 AM
Conditional Formatting based on entire column mike Microsoft Excel Worksheet Functions 7 6th Feb 2007 10:40 PM
Re: Conditional Formating based on data in an entire row Bob Phillips Microsoft Excel Setup 0 9th Jan 2007 06:35 PM
Is there a test to see if an entire row or column is empty? Henry Stock Microsoft Excel Programming 3 25th Feb 2005 05:50 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:29 PM.