+ Reply to Thread
Results 1 to 8 of 8

Replace given text and variable number

  1. #1
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Replace given text and variable number

    In certain lines in my document I have the text 'NUMBER: ' followed by a number of variable length.

    I'd like to use Find and Replace code to remove the text 'NUMBER: ' and the following number wherever it appears.

    So , for example the lines

    SEAL - FLY LIKE AN EAGLE
    126730BX320 NUMBER: 9067

    SOUL FOR REAL - EVERY LITTLE THING I DO
    166044BX90 NUMBER: 58453393

    SPACEHOG - IN THE MEANTIME
    159298BX192 NUMBER: 68229

    ASWAD - DON`T TURN AROUND
    27947BX111


    would become

    SEAL - FLY LIKE AN EAGLE
    126730BX320

    SOUL FOR REAL - EVERY LITTLE THING I DO
    166044BX90

    SPACEHOG - IN THE MEANTIME
    159298BX192

    ASWAD - DON`T TURN AROUND
    27947BX111


    Can someone suggest some code to satisfy this?

    I'll attach a sample file.


    Grateful for any advice.

    Attached Files Attached Files
    Last edited by CDandVinyl; 12-26-2023 at 10:07 PM.
    Using Excel , Word and Access 2003 - For the whole of 2024

  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: Replace given text and variable number

    I suggest you first do a format cleanup to make your data consistent. You are using at least three different formats, which makes this harder.

    Do a Find and Replace
    Check the box for "Use wildcards"

    For numbers followed by a paragraph mark:

    Find:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Replace:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    For numbers followed by a manual line break:

    Find:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Replace:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    For numbers followed by a tab then a manual line break:

    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Replace:
    Formula: copy to clipboard
    Please Login or Register  to view this content.

    Replace All

    I may have missed some variations.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  3. #3
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,005

    Re: Replace given text and variable number

    Another way,

    1. Ctrl+H
    2. More>>
    3. Checked 「Use wildcards」
    4. Find what: NUMBER*[^l^13]
    5. Replace with: ^l
    6. Replace All

  4. #4
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: Replace given text and variable number

    6StringJazzer - Many thanks for your help. I ran the Find and Replace rules you suggested and found it clears the majority.

    Sorry it not as straightforward as we'd have liked. I'm still trying to clear the lines with

    NUMBER: 819180

    NUMBER: 849120

    in the sample file.


  5. #5
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: Replace given text and variable number

    windknife - thanks. That clears all target references.

  6. #6
    Forum Expert
    Join Date
    04-14-2009
    Location
    Taiwan
    MS-Off Ver
    Excel 2016,2019,O365
    Posts
    2,005

    Re: Replace given text and variable number

    You are welcome.
    -----------------------------------
    If that takes care of your original question, please click on "Thread Tools" from the menu link above and mark this thread as SOLVED.

  7. #7
    Forum Contributor
    Join Date
    01-18-2013
    Location
    London
    MS-Off Ver
    Excel 2003
    Posts
    641

    Re: Replace given text and variable number

    Thanks guys - problem solved!

  8. #8
    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: Replace given text and variable number

    Quote Originally Posted by windknife View Post
    Another way,

    1. Ctrl+H
    2. More>>
    3. Checked 「Use wildcards」
    4. Find what: NUMBER*[^l^13]
    5. Replace with: ^l
    6. Replace All
    Nothing succeeds like success! I was trying to avoid a solution that would wipe out any text that would follow the numbers. Sometimes examples can be deceiving. If numbers are always the last thing on the line, then this is a great solution.

+ 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] Find number in parenthesis and replace with text and increasing number
    By lamdathoa in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-06-2020, 10:09 AM
  2. [SOLVED] Help to create a formula for replace a variable with a number into a cell
    By imifarma in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 04-19-2020, 10:07 AM
  3. Replies: 3
    Last Post: 02-17-2015, 11:53 PM
  4. [SOLVED] Replace text number with some other number based on the sheet
    By amandeepsharma89 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 06-03-2013, 09:52 PM
  5. search within text file and replace strings with variable number of characters
    By ingolf_ingolfsen in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 12-28-2012, 03:54 AM
  6. [SOLVED] search for text or ??? in column A, set variable or replace
    By kldailey in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-06-2012, 11:56 PM
  7. Replace variable row number in formulas
    By Ldub in forum Excel General
    Replies: 0
    Last Post: 11-03-2005, 06:30 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