Avatar of dcmathis
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.
Microsoft ExcelMicrosoft Office

Avatar of undefined
Last Comment
Saurabh Singh Teotia

8/22/2022 - Mon
Saurabh Singh Teotia

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

Saurabh...
dcmathis

ASKER
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:
CO1
CO2
CO3
CO4

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.
Saurabh Singh Teotia

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..
Your help has saved me hundreds of hours of internet surfing.
fblack61
Rob Henson

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

Thanks
Rob H
dcmathis

ASKER
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.
sample.xlsm
ASKER CERTIFIED SOLUTION
Saurabh Singh Teotia

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
dcmathis

ASKER
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.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
Saurabh Singh Teotia

You are most welcome... :-)