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.
dcmathisAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Saurabh Singh TeotiaCommented:
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...
0
dcmathisAuthor Commented:
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.
0
Saurabh Singh TeotiaCommented:
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..
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Rob HensonFinance AnalystCommented:
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
0
dcmathisAuthor Commented:
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
0
Saurabh Singh TeotiaCommented:
You can use the following code to do what you are looking for...

Sub generatetabs()
Application.DisplayAlerts = False
Application.ScreenUpdating = False

    Dim ws As Worksheet, ws1 As Worksheet, ws2 As Worksheet
    Dim rng As Range, cell As Range
    Dim lrow As Long, lr As Long, lr1 As Long
    Dim r1 As Range, c As Range


    Set ws1 = Sheets("Clients")

    'finding the lastrow of the tab range
    lr = ws1.Cells(Cells.Rows.Count, "A").End(xlUp).Row

    'setting up my range to create tabs
    Set r = ws1.Range("A2:A" & lr)

    ' Deleteing earlier sheets or data

    For Each ws In ActiveWorkbook.Worksheets

        If ws.Name <> ws1.Name And ws.Name <> "1.1" And ws.Name <> "1.2" And ws.Name <> "1.3" _
           And ws.Name <> "1.3" And ws.Name <> "1.4" And ws.Name <> "1.5" And ws.Name <> "1.5 " And ws.Name <> "1.6" And ws.Name <> "1.7" Then
            ws.Delete
        End If
    Next ws

    'starting the search

    For Each c In r
        'creating tab for this value
        Worksheets.Add after:=Sheets(Sheets.Count)
        ActiveSheet.Name = c.Value
        Set ws2 = ActiveSheet
        'Copying headers
        Sheets("1.1").Range("A5").EntireRow.Copy ws2.Range("A1")
        'starting search at each ws
        For Each ws In ActiveWorkbook.Worksheets
            'checking for correct sheet to copy data
            If ws.Name <> ws1.Name And Application.WorksheetFunction.CountIf(r, ws.Name) = 0 Then
                lrow = ws.Cells(Cells.Rows.Count, "C").End(xlUp).Row
                Set rng = ws.Range("C10:C" & lrow)
                For Each cell In rng
                    If Trim(UCase(cell.Value)) = Trim(UCase(c.Value)) Then

                        lr1 = ws2.Cells(Cells.Rows.Count, "C").End(xlUp).Row + 1
                        cell.EntireRow.Copy ws2.Range("A" & lr1)
                    End If
                Next cell

            End If

        Next ws
        ws2.Cells.EntireColumn.AutoFit
    Next c

Application.DisplayAlerts = True
Application.ScreenUpdating = True

End Sub

Open in new window


Enclosed is your workbook for your reference...
sample.xlsm
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dcmathisAuthor Commented:
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.
0
Saurabh Singh TeotiaCommented:
You are most welcome... :-)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Excel

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.