+ Reply to Thread
Results 1 to 12 of 12

Clean up numbers/text in column with macro

  1. #1
    Registered User
    Join Date
    07-31-2018
    Location
    Copenhagen
    MS-Off Ver
    2013
    Posts
    30

    Clean up numbers/text in column with macro

    Hi all,

    I am trying to create a macro/VBA to clean up a column of batch numbers in an excel sheet (can be >1000 rows).
    I need it to delete all plain text such as explanatory text and more and just return the batch numbers in a uniform matter such as "0000123456", "M1234", "1234-056789", "-" or "0000123456; 0000123456"

    I have attached an example below.

    As this is my first post here, please let me know if anything more is required :-)

    Thank you very much in advance.

    With kind regards,
    Anders

    example.jpg

  2. #2
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Clean up numbers/text in column with macro

    Your batch numbers seem to be all different formats and include non-numeric characters. How do you tell what is explanatory text and what is a batch number?
    Jeff
    | | |·| |·| |·| |·| | |:| | |·| |·|
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Registered User
    Join Date
    07-31-2018
    Location
    Copenhagen
    MS-Off Ver
    2013
    Posts
    30
    Quote Originally Posted by 6StringJazzer View Post
    Your batch numbers seem to be all different formats and include non-numeric characters. How do you tell what is explanatory text and what is a batch number?
    Hi 6StringJazzer and thank you for your reply.

    Basically batch numbers are either in the format A1234, 1234-1234567, or numbers with lengths of 10 or 12 digits. The first two should be as they are, as should the ones with LEN = 12. However all other numbers in the string with LEN from 5 to 10 should be returned with 0’s before so they all have LEN = 10 so 12345 => 0000012345.

    Does that make sense?

  4. #4
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Clean up numbers/text in column with macro

    I will take a look at this but I would like your test data in an Excel file, not an image.

    The paper clip icon does not work for attachments. Instead, under the text box where you type your reply click the Go Advanced button. On the next screen scroll down and click on Manage Attachments, which will show a pop-up window to Select and Upload a file. Then close the window.

  5. #5
    Registered User
    Join Date
    07-31-2018
    Location
    Copenhagen
    MS-Off Ver
    2013
    Posts
    30

    Re: Clean up numbers/text in column with macro

    Thank you very much :-) It is much appreciated - and sorry for the late response (I thought I would get an email notification of new actions on the thread)
    Attached Files Attached Files

  6. #6
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Clean up numbers/text in column with macro

    I'll take a look. You should be getting email notifications if your profile is set up for it. Check General Settings in your Profile.

    subscribeemails.JPG

  7. #7
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Clean up numbers/text in column with macro

    I think that your description covers most of the cases but remember, you are using your human judgement to convert these numbers, and we need an algorithm. So, for example,

    M3876, EXPIRY DATE: 31-AUG-2016

    Might come out looking like

    M3876; 000000000031; 000000002016

    When there are multiple batch numbers in the same cell, sometimes they are separated by ";" and sometimes ",". What are the rules for this? Are there other formats where there can be more than one per cell?

  8. #8
    Registered User
    Join Date
    07-31-2018
    Location
    Copenhagen
    MS-Off Ver
    2013
    Posts
    30

    Re: Clean up numbers/text in column with macro

    Thank you :-) There are in general no rules, but I have tried to dig out the most common types. They can be seperated by ";" or "," or "/". But I can probably modify the final output if needed :-)

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Clean up numbers/text in column with macro

    I have everything working except two examples that don't match anything in your description:

    4560116-0010
    3931212-0030

    Your description says:

    Basically batch numbers are either in the format A1234, 1234-1234567, or numbers with lengths of 10 or 12 digits. The first two should be as they are, as should the ones with LEN = 12. However all other numbers in the string with LEN from 5 to 10 should be returned with 0’s before so they all have LEN = 10 so 12345 => 0000012345.

    but you don't say anything about 1234567-1234.

    Can you clarify what you need here?

  10. #10
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Clean up numbers/text in column with macro

    Here is the solution, based on your description and examples. I assumed 1234567-1234 is a valid pattern.
    Attached Files Attached Files

  11. #11
    Registered User
    Join Date
    07-31-2018
    Location
    Copenhagen
    MS-Off Ver
    2013
    Posts
    30

    Re: Clean up numbers/text in column with macro

    I can not thank you enough :-) That is just working like a charm! And the 1234567-1234 pattern is indeed also a valid pattern :-) Thank you so much for all the help 6StringJazzer

  12. #12
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Clean up numbers/text in column with macro

    Glad to help, it was an interesting problem.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Excel macro to change text to numbers in a column
    By imperialzinc in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-13-2018, 04:56 PM
  2. [SOLVED] Getting Clean Telephone Numbers
    By PeteMeehan in forum Excel Formulas & Functions
    Replies: 21
    Last Post: 08-14-2016, 03:58 AM
  3. [SOLVED] Getting Clean Telephone Numbers
    By PeteMeehan in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 08-13-2016, 12:21 PM
  4. [SOLVED] Clean up phone numbers using VBA
    By needhelpwithexl in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 04-10-2014, 02:38 PM
  5. Creating a macro to clean up a text string
    By Steffen_DK in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-17-2012, 05:30 PM
  6. [SOLVED]How to clean a column to leave only certain text and numbers
    By Fosachy in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 04-20-2009, 08:13 PM
  7. Macro to Clean Text
    By ksp in forum Excel General
    Replies: 3
    Last Post: 02-27-2006, 05:03 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1