PC Review


Reply
Thread Tools Rate Thread

Delete rows where 1st 3 characters in string don't match criteria

 
 
Peruanos72
Guest
Posts: n/a
 
      14th Apr 2009
Hello all,

I have id numbers in column "E" (alphanumeric) and I want to find the cells
in column "E" where the first three characters of the id number DO NOT match
my criteria and then delete that entire row. Ex: If my criteria is "A45" and
the id numbers are "A454K90HR37" and "B47H33GT08", then I want to delete the
row containing the id number "B47H33GT08". I may have more than one set of
criteria. Ex: "A45", "B56", "987", etc... that I want to keep.

Note: I'm currently using the following code to find those cells in column
"E" where if the length of the id number is less than 16 characters the row
is deleted. Don't know if this code can be modifed to do both or not.

kpxRow = ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Row
For kpxTemp = kpxRow To 1 Step -1
If Len(Trim(Range("E" & kpxTemp))) < 16 Then
Rows(kpxTemp).Delete
End If
Next

How can I do this?

Thanks in advance!!
 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      14th Apr 2009
you're almost there

> kpxRow = ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Row
> For kpxTemp = kpxRow To 1 Step -1

If LEFT(Trim(Range("E" & kpxTemp),3) <> "A45" Then
Rows(kpxTemp).Delete
End If
> Next



"Peruanos72" wrote:

> Hello all,
>
> I have id numbers in column "E" (alphanumeric) and I want to find the cells
> in column "E" where the first three characters of the id number DO NOT match
> my criteria and then delete that entire row. Ex: If my criteria is "A45" and
> the id numbers are "A454K90HR37" and "B47H33GT08", then I want to delete the
> row containing the id number "B47H33GT08". I may have more than one set of
> criteria. Ex: "A45", "B56", "987", etc... that I want to keep.
>
> Note: I'm currently using the following code to find those cells in column
> "E" where if the length of the id number is less than 16 characters the row
> is deleted. Don't know if this code can be modifed to do both or not.
>
> kpxRow = ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Row
> For kpxTemp = kpxRow To 1 Step -1
> If Len(Trim(Range("E" & kpxTemp))) < 16 Then
> Rows(kpxTemp).Delete
> End If
> Next
>
> How can I do this?
>
> Thanks in advance!!

 
Reply With Quote
 
Peruanos72
Guest
Posts: n/a
 
      14th Apr 2009
i'm getting a syntax error on line 3. Thoughts?

And if I want to add more criteria would I seperate them
by a comma "," or something else?

Ex: ... <> "A45", "B90", "767

possible?

"Patrick Molloy" wrote:

> you're almost there
>
> > kpxRow = ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Row
> > For kpxTemp = kpxRow To 1 Step -1

> If LEFT(Trim(Range("E" & kpxTemp),3) <> "A45" Then
> Rows(kpxTemp).Delete
> End If
> > Next

>
>
> "Peruanos72" wrote:
>
> > Hello all,
> >
> > I have id numbers in column "E" (alphanumeric) and I want to find the cells
> > in column "E" where the first three characters of the id number DO NOT match
> > my criteria and then delete that entire row. Ex: If my criteria is "A45" and
> > the id numbers are "A454K90HR37" and "B47H33GT08", then I want to delete the
> > row containing the id number "B47H33GT08". I may have more than one set of
> > criteria. Ex: "A45", "B56", "987", etc... that I want to keep.
> >
> > Note: I'm currently using the following code to find those cells in column
> > "E" where if the length of the id number is less than 16 characters the row
> > is deleted. Don't know if this code can be modifed to do both or not.
> >
> > kpxRow = ActiveSheet.Cells(Rows.Count, "F").End(xlUp).Row
> > For kpxTemp = kpxRow To 1 Step -1
> > If Len(Trim(Range("E" & kpxTemp))) < 16 Then
> > Rows(kpxTemp).Delete
> > End If
> > Next
> >
> > How can I do this?
> >
> > Thanks in advance!!

 
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
Delete rows where 1st 3 characters in a cell DO NOT meet criteria Peruanos72 Microsoft Excel Programming 5 15th Apr 2009 08:46 PM
Delete rows that do not match criteria =?Utf-8?B?cmxlZTE5OTk=?= Microsoft Excel Programming 1 3rd Nov 2006 03:16 PM
VB Delete rows that do not match criteria =?Utf-8?B?cmxlZTE5OTk=?= Microsoft Excel Programming 2 1st Nov 2006 11:19 PM
Delete Rows in Worksheet2 that Match Criteria in Worksheet1!A1:A20 =?Utf-8?B?U3RldmVD?= Microsoft Excel Programming 3 22nd Jun 2006 02:56 AM
Macro to delete row based on criteria (first few characters of string) delapp@hotmail.com Microsoft Excel Programming 5 15th May 2006 06:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:09 PM.