+ Reply to Thread
Results 1 to 6 of 6

Optimizing Excel macro to find/replace with the list of data contained in the macro

  1. #1
    Registered User
    Join Date
    11-19-2006
    Posts
    5

    Optimizing Excel macro to find/replace with the list of data contained in the macro

    -Outlook 2003-

    Hi all,
    I have a macro stored in personal.xls. Someone usually sends me an excel list with a different number of users and they ask me if any of my users are in the list. The code runs the whole sheet, copies and pastes values all the data, searches for each of the names listed, and if found, replaces the value with the same value and colors the text. I have a macro that runs now but I would like to make it more efficient if possible:

    Please Login or Register  to view this content.

    The issues that I see that could happen:
    -Currently there are 28 people which means the above code is repeated about 50 times. More people may get added to my list which will make the code even longer and it doesnt seem very efficient
    -I also may want to change the search so if someone sends me a list with last name,first name or last name only, the cell will show up. But that would mean copying and pasting the text another 30-60 times

    Is there any way to combine the data? Please let me know if I can make this any clearer.
    This was also cross posted on the mrexcel forums:
    http://www.mrexcel.com/forum/showthread.php?t=359526
    Last edited by Iceyburnz; 12-17-2008 at 03:26 PM. Reason: Added version of Outlook

  2. #2
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    What is username1 and where is it given a value?

    Can you attach a sample workbook?
    Hope that helps.

    RoyUK
    --------
    For Excel Tips & Solutions, free examples and tutorials why not check out my web site

    Free DataBaseForm example

  3. #3
    Registered User
    Join Date
    11-19-2006
    Posts
    5
    Quote Originally Posted by royUK View Post
    What is username1 and where is it given a value?

    Can you attach a sample workbook?
    Username 1 is the persons username. First Last is the persons first and last name.

    The code that I posted is straight from the macro. I shortened it by not including all of the usernames and all of the first last names (it's the same snippets of code just changed to look for each of my users. It just seems like there might be a more efficient way to do this.....

  4. #4
    Registered User
    Join Date
    11-19-2006
    Posts
    5
    Here's a scenario:

    Someone from a diff team will send me a sheet and ask me if any of my users are in the sheet
    I run the macro
    If the sheet had people sorted by their usernames and UserName1 is contained; it will be highlighted in red
    If the sheet is sorted by first and last name and First last1 is in the list, the text will be highlighted in green

  5. #5
    Forum Expert royUK's Avatar
    Join Date
    11-18-2003
    Location
    Derbyshire,UK
    MS-Off Ver
    Xp; 2007; 2010
    Posts
    26,200
    I'd like to see an example to see the layout

  6. #6
    Registered User
    Join Date
    07-02-2008
    Location
    Fort Worth, TX
    Posts
    99
    Simply build an array, either in the actual workbook or elsewhere that has a list of the names to be looked for, and what to replace with, 2 columns column A has the look for, Column B has the replace with.

    Use 2 primary variables to reference those to columns and use a for loop to loop through each one until it reaches the end, repeating the primary objective with each loop. If I had time I'd build an example but I'm being run out of here so I don't get OT pay. If your still having trouble, or somone else doesn't jump on it, then I'll work on an example tomorrow on my lunch

+ 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