+ Reply to Thread
Results 1 to 10 of 10

Need VBA Code to remove number prefix if name found on another list

  1. #1
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    Need VBA Code to remove number prefix if name found on another list

    I have a challenge removing leading numbers in a list. Originally, I assume the leading number was always 5 digits in length but it turns our it can be any length. So, I need to take a different approach. I again have attached a sample.

    In the sample the tab named “Names” data on what to adjust based on what is found in the “Data” Tab. What I am looking to have the VBA code do is remove a number on the front of the name on the “Names” tab if the same name if found in the list of names in cells E2:E in the “Data” tab. I want the VBA code to walk down the list of names on the “Name” Tab starting at B5 and compare it to the names found on the Data Tab cells E2:E. I have created the “Names (desired result)” Tab to show you the results.

    The rules are:

    1) The list of names on both tabs can be of any length.
    2) If a cell on the Names Tab does not have a number in the front do nothing and go on to the next cell.
    3) If the cell has a number (of an undefined length) in front and cannot find same name from cell E2 to the end without the number prefix again do nothing and go on to the next cell.
    4) If the cell has a number (of an undefined length) in front and can find same name from cell E2 to the end without the number prefix then remove the number from the front on that cell on the “Names” tab.

    Here are some examples:

    • Cell B5 on “Names” tab finds the same name in cell E4 on the “Data” tab so Cell B5 is converted to: Advertising and Promotion
    • Cell B16 on “Names” tab finds the same name in cell E11 on the “Data” tab so Cell B16 is converted to: 2018YTD Credit Card Fees where the 4523 is removed.
    • Cell B8 on “Names” tab has no number prefix, so the code does nothing to cell B8.

    I hope all this makes sense. I am look forward to a nice clean solution. You people on this Forum are all great!!
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Need VBA Code to remove number prefix if name found on another list

    Try
    Please Login or Register  to view this content.
    - Battle without fear gives no glory - Just try

  3. #3
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    Re: Need VBA Code to remove number prefix if name found on another list

    Quote Originally Posted by PCI View Post
    Try
    Please Login or Register  to view this content.
    Hi PCI, It appears to be working perfectly. Thanks you so much.

  4. #4
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    Re: Need VBA Code to remove number prefix if name found on another list

    Quote Originally Posted by PCI View Post
    Try
    Please Login or Register  to view this content.
    Hi PCI, I tested it with a real group of data and the "Names" Tab had an account named "Federal Taxes" with no number prefix. On the DATA Tab was the same name "Federal Taxes" But your VBA code removed the word "Federal" from that the "Federal Taxes" cell which is incorrect. I cannot figure out why, can you?
    Last edited by Bobbbo; 04-10-2018 at 07:30 PM. Reason: Typo

  5. #5
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,523

    Re: Need VBA Code to remove number prefix if name found on another list

    1)
    Don't quote whole post.
    If you are responding to a post out of sequence, limit quoted content to a few relevant lines that makes clear to whom and what you are responding

    For normal conversational replies, try using the QUICK REPLY box below.

    2)
    Try this
    Please Login or Register  to view this content.

  6. #6
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Need VBA Code to remove number prefix if name found on another list

    Yes, was missing a test
    Try next code

    Please Login or Register  to view this content.

  7. #7
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    Re: Need VBA Code to remove number prefix if name found on another list

    Hi PCI, That appears to work correctly now. I still need to do more testing before I edit this email to be marked "SOLVED". Thanks again!

  8. #8
    Forum Expert
    Join Date
    12-24-2007
    Location
    Alsace - France
    MS-Off Ver
    MS 365 Office Suite
    Posts
    5,066

    Re: Need VBA Code to remove number prefix if name found on another list

    "I still need to do more testing "

    Oh!!! yes ... check and recheck

  9. #9
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Hi ! Try this !


    An EZ way :

    PHP Code: 
    Sub Demo1()
         
    Dim VARg As RangeV
             VA 
    Range("Data!E2").CurrentRegion.Value
        
    For Each Rg In Range("Names!B5").CurrentRegion
              
    If Rg.Value Like "#*" Then
                  V 
    Application.Match(Mid(Rg.ValueInStr(Rg.Value" ") + 1), VA0)
                  If 
    IsNumeric(VThen Rg.Value VA(V1)
              
    End If
        
    Next
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !

  10. #10
    Forum Contributor
    Join Date
    04-05-2010
    Location
    Lakewood, IL
    MS-Off Ver
    Excel 2016
    Posts
    384

    Re: Hi ! Try this !

    Hi Marc L, Your code appears to work as well. I will continue testing. Thanks

+ 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. [SOLVED] Return MIN from a list After MAX is found - MIN number to the right of MAX
    By RidgeRunner in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 03-22-2018, 08:45 AM
  2. [SOLVED] Remove prefix of varying lenghts
    By jimbokeep in forum Excel General
    Replies: 6
    Last Post: 01-16-2017, 09:57 AM
  3. If this number has been found in a list than copy its text and value there
    By theultimateking1 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-30-2015, 11:37 PM
  4. replace code/id values with a name found in a list
    By ebbo in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-10-2015, 10:25 AM
  5. [SOLVED] Search for the text in cell A1 in a list and remove the text if found in the list
    By kak0 in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 07-24-2014, 11:01 PM
  6. Not found the color code list in outloo
    By joe41 in forum Outlook Programming / VBA / Macros
    Replies: 1
    Last Post: 03-30-2009, 03:19 AM
  7. Can I remove prefix apostrophe
    By swansonwc in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 01-15-2006, 06:03 PM

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