?
Solved

Data cleansing puzzle

Posted on 2014-03-11
5
Medium Priority
?
181 Views
Last Modified: 2014-03-11
See attached.

For the sake of the example.

Assume that I sell car parts.

Column A is the part number.
Column B is supposed to be a serial number - but there was no validation on this field and there is all sorts of funny values.

I want to extract potential VALID serial numbers data from column B and put it into column C.

See example in sheet.

A serial number is deemed to be valid if there are 4 (or more) numeric digits in a row.

E.g.
123456CATS is valid - ie. 123456
123CATS1234 is NOT valid
19090CATS123 is valid - i.e. 19090

It may be easier to follow in the attached sheet.

Objective: Populate column C with valid serial number that are found in column B.
SerialNumbersPuzzle.xlsm
0
Comment
Question by:Patrick O'Dea
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 46

Accepted Solution

by:
aikimark earned 2000 total points
ID: 39921333
Add this function to your project:
Option Explicit

Public Function GetPartNum(parmSN)
    Static oRE As Object
    Static oMatches As Object
    If oRE Is Nothing Then
        Set oRE = CreateObject("vbscript.regexp")
        oRE.Global = True
        oRE.Pattern = "(\d{4,9})"
    End If
    If oRE.test(parmSN) Then
        Set oMatches = oRE.Execute(parmSN)
        GetPartNum = oMatches(0).submatches(0)
    Else
        GetPartNum = vbNullString
    End If
End Function

Open in new window

Then add a formula that invokes the function into the cells you want populated with the part number.
Example:
=getpartnum(B2)

Open in new window

0
 
LVL 33

Expert Comment

by:Rob Henson
ID: 39921388
Why wouldn't example 2 123CATS1234 be valid? It has 4 digits in a row.

Or does the 4 digits have to be at the beginning?

If just the first 4 characters have to be a number then you can use the ISNUMBER function.

Assuming serial number in A2:

=ISNUMBER(LEFT(A2,4)*1)

The *1 forces excel to recognise the result as a number rather than a string of text that happens to look like a number.

You can then wrap that within an IF statement to get Valid / Invalid:

=IF(ISNUMBER(LEFT(A2,4)*1),"Valid","Invalid")

Thanks
Rob H
0
 

Author Comment

by:Patrick O'Dea
ID: 39921843
Thanks for comments.

Rob H , you spotted an error in my sheet.  The digits do NOT have to be at t he beginning.  They can be anywhere.

I will evaluate aikimark's suggestion now.
0
 

Author Comment

by:Patrick O'Dea
ID: 39921873
aikimark,

I have done as you suggest but get #NAME?


See attached.

Cell D2

(I am obviously missing something ... the function does not seem to be recognised)??
SerialNumbersPuzzle.xlsm
0
 

Author Closing Comment

by:Patrick O'Dea
ID: 39922072
Thanks !

Works very well.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
This article describes how you can use Custom Document Properties to store settings and other information in your workbook so that they will be available the next time you open the workbook.
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question