+ Reply to Thread
Results 1 to 7 of 7

Macro for Find and replace function

Hybrid View

  1. #1
    Registered User
    Join Date
    03-31-2015
    Location
    Greece
    MS-Off Ver
    Microsoft Office 2007
    Posts
    6

    Macro for Find and replace function

    Hello evryone,
    Im new to this forum and i dont speak english very well.
    I need help to build an excel file for inventory/stock check.
    The find and replace function is not working the way i need to.
    I have like 1800 different products in my inventory, for example i want to find a product named ''Dishwasher Fairy 2.5Lt'' i type in find and replace(Ctrl+F) ''dish'' and it brings me all the names that contains ''dish'' in.
    What i want is a macro to make Find and replace to bring me all the words that only STARTS with ''dish''.
    I hope you understand what im trying to say.
    Thank you.

  2. #2
    Valued Forum Contributor
    Join Date
    01-10-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    651

    Re: Macro for Find and replace function

    this should be possible without vba - in your find box, type dish*
    and then in the advanced options check "Match entire cell contents"

    if you really want the vba, i recorded this while doing the steps above and this seems to be doing what you want:

    Cells.Find(What:="dish*", After:=ActiveCell, LookIn:=xlFormulas, LookAt _
            :=xlWhole, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Activate
    Hope I could help - if your post has been solved don't forget to mark it as such.

    Clicking the * below is a great way to say thanks!

    "Drowning in 10 feet of water isn?t any different than drowning in a million feet. And if you can swim, it doesn?t matter how deep the ocean is. At some level, once you realize you?re in water that?s too deep to stand, you have to have a very different approach," - Joi Ito

  3. #3
    Registered User
    Join Date
    03-31-2015
    Location
    Greece
    MS-Off Ver
    Microsoft Office 2007
    Posts
    6

    Re: Macro for Find and replace function

    Hello simarui thank for the reply,
    The macro you gave me is finding all the cells have dish in it, but its not what i wanted, maybe i didnt explain what i need really good.
    Lets say i have 10 products with different names for example:
    Soap X
    Soap X
    Powder A
    Powder C
    Liquid G
    Liquid K
    Sponge T
    Sponge Z
    Detergent P
    Detergent w
    Now i want to Find ''Detergent P'' so i press Ctrl+F(which open the Find & Replace window) then type ''De" and press find, then excel gives me the "Powder A" first because it contains the letter ''De'' in it. I want to mondify the Find & Replace function so when i type some letter in it it will give me only the results that starts with the letter i typed in.

    Hope this time i made clear my needs.
    Thank you again simarui for your time and effort.

  4. #4
    Registered User
    Join Date
    03-30-2015
    Location
    Barbados
    MS-Off Ver
    2013
    Posts
    4

    Re: Macro for Find and replace function

    Hi. If you have not done so you should consider putting this data in an Excel table and use Excel's default table search function. I know this does not directly answer your question but from the outside looking in it seems to be a much simpler solution than trying to reinvent the wheel.
    Feel free to visit my store at www.ebdapps.com

  5. #5
    Valued Forum Contributor
    Join Date
    01-10-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    651

    Re: Macro for Find and replace function

    you cannot simply put "de" you need to type in "de*". The * is called a wildcard and tells excel to look for anything beginning with de - it can end with anything else. (you can also search for "*er" and find anything which ends in "er") also, after hitting ctrl + f you need to press the Options button, and select "Match Entire Cell Contents". The macro handles that step with the line "LookAt:=xlWhole" so i'm surprised at your comment "the macro ... is finding all the cells have dish in it", that should not be happening if you copied that line exactly
    Last edited by simarui; 04-01-2015 at 03:20 PM.

  6. #6
    Registered User
    Join Date
    03-31-2015
    Location
    Greece
    MS-Off Ver
    Microsoft Office 2007
    Posts
    6

    Re: Macro for Find and replace function

    Simarui, just making sure we are on the same page, i ll explain you what i did and you tell me if did anything wrong.
    I' ve created a Search box then i double click to insert the code you gave me and save it.

  7. #7
    Valued Forum Contributor
    Join Date
    01-10-2012
    Location
    Texas
    MS-Off Ver
    Excel 2010
    Posts
    651

    Re: Macro for Find and replace function

    Sorry Alpha_Mike,

    I don't know what you mean by "Search box." but, if you search for "de*" and either select "Match Entire Cell Contents" in the find & replace window, or if you use the vba i provided and replace "What:="dish*"" with What:="de*" or some .value type reference to any range or input box or however you want to define your search parameter, then it should skip Powder and only pull in Detergent (or any other cell which starts with the letters de).

    did something not work after trying either of those two methods? what did not work? Can you upload a sample workbook showing your code / "Search box" / dataset and demonstrating what about the solution is not working?

+ 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. Replies: 3
    Last Post: 11-25-2014, 06:08 AM
  2. Create A Macro Button for a Find and Replace Function
    By Fredbugatti in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 05-18-2014, 06:50 PM
  3. Macro to Perform Find and Replace Function Please HELP!
    By Elizabethd1012 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-08-2014, 07:13 PM
  4. Find/Replace Macro Using Replace Table
    By LampCommandr in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 10-24-2011, 11:00 AM
  5. Advanced Find and Replace function or macro help
    By johnmalcolm in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 01-11-2007, 11:01 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