+ Reply to Thread
Results 1 to 5 of 5

Replacing many values

  1. #1
    Registered User
    Join Date
    08-10-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    2

    Replacing many values

    Hi

    I have a large amount of changes I need to make in an Excel workbook. This is changing codes to something legible for instance:

    HYT564 = SCANNER

    I can obviously use find and replace but this would be a long process since there are about 80 codes that need changing and this process needs to be done every month. Is there any way you can write a macro and then run this across the whole sheet so that it replace all the codes? If so I would appreciate help of how this would be wriiten.

    Thanks
    David

  2. #2
    Forum Expert contaminated's Avatar
    Join Date
    05-07-2009
    Location
    Baku, Azerbaijan
    MS-Off Ver
    Excel 2013
    Posts
    1,430

    Re: Replacing many values

    Can u not use wildcards if all codes starts with HYT... or even H
    Like

    In find what field type HYT* or H* if they all starts with H and replace 'em with anything u want.
    Люди, питающие благие намерения, как раз и становятся чудовищами.

    Regards, ?Born in USSR?
    Vusal M Dadashev

    Baku, Azerbaijan

  3. #3
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Replacing many values

    this should do it
    replaces stuff in column A from a list in B and C (B=old C=new)
    Please Login or Register  to view this content.
    if however your cells to change arent in one row but across a range on sheet you can change it and your find replace list so suit
    eg range is in cols a,b,c,d and replace list list is in cols E/F
    then
    Please Login or Register  to view this content.
    note this is not written for excel 2007 but as long as you dont go above 65536 rows it should work(i'm just of to my other machine to test it! and it does )

    place code in a new module and run from tools/macro/macros
    for 2007 thats
    developer tab/macros (if you cant see developer tab )
    office button/excel options and in the top options for working with excel pane check "show developer tab in ribbon" option
    see link my signature for where to put code
    Last edited by martindwilson; 08-10-2009 at 07:52 AM.
    "Unless otherwise stated all my comments are directed at OP"

    Mojito connoisseur and now happily retired
    where does code go ?
    look here
    how to insert code

    how to enter array formula

    why use -- in sumproduct
    recommended reading
    wiki Mojito

    how to say no convincingly

    most important thing you need
    Martin Wilson: SPV
    and RSMBC

  4. #4
    Registered User
    Join Date
    08-10-2009
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    2

    Re: Replacing many values

    Hi Martin

    thanks for the reply, I am very impressed with the speedy and thorough answer! However at the risk of being irritating can you please explain exactly where the items for changing should be entered? For example here are 2 of the example codes that need switching:

    HRDW-SWTC Switch*
    MSCL-BSBL Base Builds*

    I am not used to writing macros and so would appreciate if you could spell where they need to go exactly in the code.

    By the way it would be your second solution since they are likely to be scattered around the sheet.

    Thanks for your time, it is appreciated.

    David

  5. #5
    Forum Expert martindwilson's Avatar
    Join Date
    06-23-2007
    Location
    London,England
    MS-Off Ver
    office 97 ,2007
    Posts
    19,320

    Re: Replacing many values

    in the second example i used column e but you can change that to any spare column,(thats two columns one to hold old value,and one next to it,on the right to hold new)
    in column e put old value in column f put corresponding new value
    the macro will search each cell in a:d (also changable)
    thats this bit
    Please Login or Register  to view this content.
    and look for the first value in col e
    thats this part
    Please Login or Register  to view this content.
    (E1)if it finds it it will replace it with that in column f (F1).
    this bit says
    Please Login or Register  to view this content.
    use the value 1 column to the right,
    it then repeats the process searching for second value in column e (E2) and if found replace with value in col f (f2)

+ 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