Using alphanumeric and numeric criteria in same code

P

Peruanos72

I was given the following code and it works but I need to also add criteria
that is numeric only. When I add numeric only criteria it does not work.
Thoughts??

Sub DeleteRows()
Dim kpxRow As Long
Dim kpxTemp As Long
Const Criteria As String = "Y08,Y09"
With ActiveSheet
kpxRow = .Cells(.Rows.Count, "E").End(xlUp).Row
For kpxTemp = kpxRow To 1 Step -1
If InStr("," & Criteria & ",", "," & Left(.Cells(kpxTemp, _
"E").Value, 3) & ",") Then .Rows(kpxTemp).Delete
Next
End With
End Sub
 
P

Patrick Molloy

if you use numbers, then does your function LEFT(....,3) need to be changed
to ,2) ?
 
R

Rick Rothstein

It works for numbers like 123 and 456 (I just tried it), so you will need to
show us the Const statement you are using (so we can see how you are
specifying your numbers) and tell us how the number is formatted (if at all)
in the cells of Column E.
 
R

Rick Rothstein

When the OP asked this question originally, he specified he needed to work
with the first 3 characters and posted this as an example...

Ex: "A45" and "987" ect...
 
P

Peruanos72

It works now. it was the formatting and how I was importing the file into
excel.

Thanks!!
 
P

Peruanos72

i'm not sure. Not to experienced with code but i'm learning. The formatting
of the
cells did the trick though. Thx anyway.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top