+ Reply to Thread
Results 1 to 9 of 9

Find and Replace all - Macro with user input

  1. #1
    Registered User
    Join Date
    07-11-2009
    Location
    -
    MS-Off Ver
    Excel 2003
    Posts
    46

    Find and Replace all - Macro with user input

    I would like to create a macros that asks the user for an "input" like with a prompt box. The Macros will search through the worksheet and replace the input by deleting whatever cells it is in.
    I would like to do this twice, with two different inputs.

    I was wondering if one could do this with partially complete inputs..
    For instance I enter "red" in the prompt box, and it finds and deletes all cells with instances of "red dog" and "red" and "red tie".

    Thank you so much for your help in advance.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Find and Replace all - Macro with user input

    Use Ctrl+H to bring up the Find & Replace dialog.
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    07-11-2009
    Location
    -
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: Find and Replace all - Macro with user input

    yes i know but I want to add code to the beginning of a macros where a user can input text through two prompt boxes and it will find and delete all cells that contain that input. I was wondering if someone can tell me the code I should insert

  4. #4
    Registered User
    Join Date
    07-11-2009
    Location
    -
    MS-Off Ver
    Excel 2003
    Posts
    46

    Re: Find and Replace all - Macro with user input

    Like I understand if I press record and do the find all and replace feature, I should be able to get the code for that. Thats great, but I do not know how to get the two prompt boxes to show up. So that the user after running the macros will be requested to type in two inputs that should be searched for in the spreadsheet and replaced. Thanks once again if you can help. I dont think its a difficult question.

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Find and Replace all - Macro with user input

    The following code will create the Input Boxes you require. You will need to write a Find routine to process these items and, yes, one can
    do this with partially complete inputs
    Please Login or Register  to view this content.
    If you haven't figured this out yet, let me know.
    J

  6. #6
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Find and Replace all - Macro with user input

    I had some time on my hands this evening as my house guests left earlier today. The attached workbook may be of some use to you. It will clear the contents of cells of all instances of the user prompts (with a wildcard). If the user enters "red" and "green" , it will clear "red", Red", "red bull", "red ball", "green", "Green", "green apple", etc.

    Let me know how you make out.

    J

    PS: I found a bug in this worksheet; I've deleted the attachment. Will find a fix and repost.
    Last edited by jaslake; 07-19-2009 at 10:05 PM.

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Find and Replace all - Macro with user input

    The attached workbook macros will prompt the user for two input values and will then delete (clear the contents) of all cells in the worksheet of those values. It uses a wildcard such that if the user enters "red" and "green" , it will clear "red", Red", "red bull", "red ball", "green", "Green", "green apple", etc.

    Please note, the macro requires the entry of two values. It can be modified to accept only one value but your specs indicated two.

    Let me know how you make out.
    J
    Attached Files Attached Files
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  8. #8
    Forum Contributor
    Join Date
    02-23-2006
    Location
    Near London, England
    MS-Off Ver
    Office 2003
    Posts
    770

    Re: Find and Replace all - Macro with user input

    You may find this quicker as it uses Excels built in Find function, but I'm not sure how much faster it would be. It would depend on the size of your data set.

    Please Login or Register  to view this content.
    I have coded slightly differently to Jaslake, in that you can choose to have as many inputs as you like, and must use the [Cancel] button on the input box, (as directed) to exit the macro.
    If you find the response helpful please click the scales in the blue bar above and rate it
    If you don't like the response, don't bother with the scales, they are not for you

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Find and Replace all - Macro with user input

    I like it Phil.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Tags for this Thread

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