Link to home
Start Free TrialLog in
Avatar of dcmathis

asked on

Trying to create a macro to copy text from a cell, work with that text, and then copy text from the next cell and work with that text

I've been given an excel spreadsheet with seven tabs in it, all with pre-designed search filters on column C.  and all with several thousand rows of data.  I need to take the first of several company names, filter each of the seven tabs for that name, copy the resulting record , and combine all data for that company name in a new sheet in a single tab.  I used recorder to get the procedure to work, but only for a specific cell with the macro code showing the actual text that I"m copying.  

I need to be able to use a list of company names, and have the routine copy the text from the first one, process the searches, collect the results into a new tab, and then go back to copy the next text and repeat.
Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

Can you post your sample workbook as it will be easy to write a code for you to do what you are looking for...

Avatar of dcmathis


Sorry, but I can't do that.  It's privileged information.  Wish I could.  I've got the basic procedure working correctly, but I need to move down to the next value on the list and run the routine again with the new search value.  

Example value list:

Open in new window

I grab the text from the first value, "CO1" and fliter the data tabs by that value, and then copy the results for each tab into a new tab.  Then I need to move down the list and get the value "CO2" and repeat.
Okay help me answer these questions...

1. Where is this range based on which you want to search? Which sheet has these values?
2. What is the sheet name where you want to place data?
3. What is the range from each sheet that you want to copy?
4. In your workbook do you have 9 sheet tabs only... assuming 7 for copy..1 for input of filter and 1 for paste of the data or you have more sheets?
5. In 7 sheet tabs i'm assuming C is the column where you have matching values...

if you can help me answer these questions i can write a macro for you...

Also at the same time you can create a dummy workbook for posting as it will help to write a code in a faster manner..
I suspect you can enclose your existing script within a For Next Loop.

Assuming you highlight the list above (C01 to C04) you can then use:

For Each Cell in Selection

CompanyName = Cell.Value
"Insert Existing routine here replacing hard coded values with CompanyName as a variable"

Next Cell

Open in new window

Rob H
Possibly.  However, it appears that I've got bigger problems than that.  I saved the spreadsheet as a new file and went in and scrambled the data.  Now when I run the existing macro, the data that's returned isn't the correct data (It should return the date for CO1).  However, it returns the data in the row that the original macro recording returned (in this case row 990).  Here's the file, such as it is.  The company name list is in the CLIENTS tab, and it's written so that it creates a new spreadsheet for the results.  What I really need is to create a new tab for each result, so I'd have a CO1 tab, a CO2 tab, etc.
Avatar of Saurabh Singh Teotia
Saurabh Singh Teotia
Flag of India image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thank you!  I can work with this.  Now to do the second part (which I was just told about).  Hopefully I can figure this part out by myself.
You are most welcome... :-)