+ Reply to Thread
Results 1 to 8 of 8

Replacing first 4 digits with ****

  1. #1
    Registered User
    Join Date
    01-29-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    4

    Question Replacing first 4 digits with ****

    Hi,

    Very, very new to vba so please bear with me. I am currently working with a sheet that has different amounts of data per cell that contains a mixture of words and numbers (again random amounts). What I'm trying to do is:

    1. Find all the numbers in any cell that has 8 digits
    2. Replace the first 4 digits of each of those numbers with ****

    Like I mentioned, I'm new to vba, the most I've achieved so far is to record a macro to do a couple of things. I started replacing the first 4 digits manually but the list is getting longer and the data per cell is increasing too....... any suggestions please.

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Replacing first 4 digits with ****

    Welcome to the forum.

    Can you post some sample data so we'll know what you're working with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Registered User
    Join Date
    01-29-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Replacing first 4 digits with ****

    Wow, thanks for the quick response!!

    OK, a cell might have some thing like this:

    i need to remove numbers 34567 12345678 before my boss 00000 99999999 fires me.

    Or it may contain more data like:

    yesterday my leg was broken 11111 63598546 22222 69875462 33333 65489546 but due to a quick fix 44556 95462357 i managed to 78546 95462348 walk again today.

    I am having change the numbers manually to look like;

    i need to remove numbers 34567 ****5678 before my boss 00000 ****9999 fires me.
    or
    yesterday my leg was broken 11111 ****8546 22222 ****5462 33333 ****9546 but due to a quick fix 44556 ****2357 i managed to 78546 ****2348 walk again today.

    I am working with account numbers that need to be passed onto developers so they can fix the faulty code but due to policy they are not allowed to see the full account number.

    Thanks

  4. #4
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Replacing first 4 digits with ****

    I don't know what happened to your post. It looked like a coded message.

    I pulled this information from it:
    I need to remove numbers before my boss fires me.

    it may contain data like:
    34567 12345678
    00000 99999999
    11111 63598546
    22222 69875462
    33333 65489546
    44556 95462357
    78546 95462348

    I am having change the numbers manually to look like;

    34567 ****5678
    00000 ****9999
    11111 ****8546
    22222 ****5462
    33333 ****9546
    44556 ****2357
    78546 ****2348
    If that is accurate, then:
    With A1:A7 containing these values:

    Please Login or Register  to view this content.
    This formula replaces the 1st four digits of the second set of digits with asterisks:
    Please Login or Register  to view this content.
    Copy that formula down through B7.

    With the above data, the formulas return these values:

    Please Login or Register  to view this content.


    Copy the Col_B calculated values and past_special.values over the Col_A values.
    Then delete the Col_B formulas.

    Does that help?

  5. #5
    Registered User
    Join Date
    01-29-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Replacing first 4 digits with ****

    Hi,

    Not quite, I have added a sample excel file which might explain it a little better. Column C and D (not that D has anything in it yet) will hold the same kind of data of varied amounts.
    Hope that explains it better.
    Attached Files Attached Files

  6. #6
    Forum Guru romperstomper's Avatar
    Join Date
    11-04-2008
    Location
    A1
    MS-Off Ver
    Most
    Posts
    12,302

    Re: Replacing first 4 digits with ****

    Try this - it runs on all data in column C but you can adjust if required.
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  7. #7
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: Replacing first 4 digits with ****

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    01-29-2010
    Location
    Scotland
    MS-Off Ver
    Excel 2003
    Posts
    4

    Re: Replacing first 4 digits with ****

    Genius!!!! Thanks romperstomper, works perfectly!!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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