+ Reply to Thread
Results 1 to 9 of 9

Macro to Search(Find) specific word from list, and copy a cell referenced from each

  1. #1
    Registered User
    Join Date
    05-30-2013
    Location
    US
    MS-Off Ver
    2013
    Posts
    67

    Macro to Search(Find) specific word from list, and copy a cell referenced from each

    Problem: I have a list in Sheet1 ("Main") in Column X that is dynamic in length every time I run the program. The list will be used as the search parameter for each search until the list has ended.
    I would like the program then to start with the first row in Sheet 1 Column X as the search term, ie: Morrison Maierle and then search Sheet 2 ("NoRetention") for the match throughout the sheet in column K, and each time it finds word I would like it to reference a cell that is 8 column away from it in column S.

    Keep doing this for every instance of the word and then total up the amounts in Column S.

    Solution: I have thought up so far a solution that does not work but I think is close to there. I have written it out to copy all cells into Column W. What I have not done is make it total up everything in Column Y and place that amount in the same row as the name it search Morrison Maierle in Column Y.

    Goal: When the program is done I have a neat list of column X companies, and column Y of total amounts it found in Sheet2("NoRetention") that were added up from Column W.

    Code so far:
    Please Login or Register  to view this content.

    Also have attached a sample test book of the problem.
    Attached Files Attached Files

  2. #2
    Registered User
    Join Date
    05-30-2013
    Location
    US
    MS-Off Ver
    2013
    Posts
    67

    Re: Macro to Search(Find) specific word from list, and copy a cell referenced from each

    Should these two functions of adding and collecting the data be combined into two subs?

  3. #3
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro to Search(Find) specific word from list, and copy a cell referenced from each

    Are you adding up column S, not W since you do not have data in column W?

  4. #4
    Registered User
    Join Date
    05-30-2013
    Location
    US
    MS-Off Ver
    2013
    Posts
    67

    Re: Macro to Search(Find) specific word from list, and copy a cell referenced from each

    Yes AB33, I am trying to add up column S with the rows that correlate with the search parameter in column K.

  5. #5
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro to Search(Find) specific word from list, and copy a cell referenced from each

    Try the attached.
    Attached Files Attached Files

  6. #6
    Registered User
    Join Date
    05-30-2013
    Location
    US
    MS-Off Ver
    2013
    Posts
    67

    Re: Macro to Search(Find) specific word from list, and copy a cell referenced from each

    It works flawlessly holy hell!

    Thank you AB33, you a coffee drinker? I will make it a goal to find a way to send you a cup of coffee on me at your local starbucks


    In the mean time it is pissing me off that I do not understand your code.

    Please Login or Register  to view this content.
    **This declares the range to be X as the searchable field in "NoRetention" as K1 to the end of column K and including column S

    The next part is a little archaic to me, do you create a Scripting Dictionary to hold all the values of each company and then use the dictionary to do math?

    I have never seen something look like this, as my example is much much different. Is this kind of information/knowledge a relatively basic programming step?

  7. #7
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: Macro to Search(Find) specific word from list, and copy a cell referenced from each

    I am very coffee sensitive person. I am afraid, the latte and coffee of Starbucks are VERY Dreadful. Coffee making is not a formula, but an art. If you have local Italian coffee shop, I will have a Weak latte.
    Please Login or Register  to view this content.
    Column K is the first column and S is the last one. I am normally lazy and use Current region, but not in this instance as you have complete blank columns.
    Assigning(Copying) the range in to an array called X and this speeds the execution of the code.
    Dictionary holds unique keys with items.
    Loop through the array(X) and test each row for existence of a key. But the actual code is more complicated than merely looping through arrays.
    Before you venture out in the world of dictionary, it is a good idea to have a solid grasp of Arrays.
    Last edited by AB33; 10-28-2013 at 06:04 PM.

  8. #8
    Registered User
    Join Date
    05-30-2013
    Location
    US
    MS-Off Ver
    2013
    Posts
    67

    Re: Macro to Search(Find) specific word from list, and copy a cell referenced from each

    AB33 I have gone and taken your code and think I learn more of the scripting dictionary. I wanted to try and create your program onto another sheet to do darn near the same thing. So I tweaked the column references inside the array to accommodate the different sheet.

    This looks like it would work, the biggest difference in this list is that the list now might not contain the name from the main list. The code I have from you that is altered:

    Please Login or Register  to view this content.
    Attached is a updated Test Excel File to view the new sheet that was added.
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    05-30-2013
    Location
    US
    MS-Off Ver
    2013
    Posts
    67

    Re: Macro to Search(Find) specific word from list, and copy a cell referenced from each

    Shouldent this script modified to another worksheet work? However right now it just deletes my columns in my main sheet.

+ 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. VBA Macro for search specific word and input specific value
    By Toton6868 in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 01-10-2013, 07:14 AM
  2. Macro to search sheet for certain criteria and copy specific data to cell
    By ThaGonz in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-02-2012, 12:34 PM
  3. Replies: 13
    Last Post: 08-04-2011, 09:41 AM
  4. Replies: 1
    Last Post: 01-25-2011, 10:50 PM
  5. [SOLVED] search for a specific word and copy the word and the preceeding words until a comma
    By DHANANJAY in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 12-31-2005, 09:10 AM

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