Excel 2010; copy per subtotal to new sheet

Posted on 2013-12-09
Last Modified: 2013-12-10
Hi Experts,

I have data to be subtotalled 'per user',
Since I have to email the data to each of those users I wondered if there was a way to copy the rows  that belong to a particular user to a seperate sheet.
Attached a custom file.
Thanks a lot.

Question by:Watnog
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 5
LVL 33

Expert Comment

by:Rob Henson
ID: 39705662
Have a look at the Advanced Filter Function.

This can filter to another location (within the same workbook) which can then be copied/exported out for sending to your users.

Rob H

Author Comment

ID: 39705757
Thanks Rob. Yes that would work, only it still remains a manual thing to do (create a filter per user). Since in this case the user count is almost 300, I'd rather have this in a macro.
LVL 33

Expert Comment

by:Rob Henson
ID: 39705778
It could be automated to run through a list of users and change the filter for each and create the sheet for each.

Rob H
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.


Author Comment

ID: 39705870
Do you know how by any chance?
LVL 33

Expert Comment

by:Rob Henson
ID: 39705900
Yes, but I would need a sample file to work on.

I assume each user will have multiple entries in data list so will also need a list of users with single entry per user. For purposes of upload, this can be fictitious so as not to divulge sensitive info eg User1, User2, User3 etc.

For the data list, I would need the column headings and sample sample rows, 20+ should suffice but again fictitious data.


Author Comment

ID: 39706013
I hope the attached file is good enough.
So for all "jobs" that belong to the same "on call job-manager" a seperate worksheet needs to be created. Please try to have the entire row selected/exported (not all columns are in the sample file).
Many thanks and good luck.

LVL 33

Accepted Solution

Rob Henson earned 500 total points
ID: 39706271
Try the attached.

In addition to original data, I have added:

Range Names
On Data tab:
JOB_DATA  Refers to all data on Data tab. Range is dynamic using following formula:
This creates a range starting at Data!$A$1 and counts the entries in column A and row 1 to determine height and width of range. Assumes continuous data in column A and row 1; I added a # to row 1 of your coloured column just so it gets included.

Summary tab:
MANAGER_LIST  This refers to the list on Summary tab. This list is actually a simple Pivot Table using JOB_DATA as its source data. Again Dynamic, using:
The count of column is reduced by 1 to allow for Row Header.

On Info tab:
MGR_COUNT  Counts number of Managers from MANAGER_LIST

MGR_NUMBER  Number of Current Manager in Filter Routine

MGR_NAME  Name of Current Manager in Filter Routine.

For those that like to see the routine without downloading the whole file, it copied below.

Sub Filter()

Application.DisplayAlerts = False

'Clear Old Sheets
For Each Worksheet In ActiveWorkbook.Worksheets
ShtName = Worksheet.Name

Select Case ShtName
    Case "Info", "Data", "Summary"
    Case Else
    GoSub ClearSheet
End Select

Next Worksheet

'Reset List

'Create New
For Mgr = 1 To Range("MGR_COUNT")
    Range("MGR_NUMBER") = Mgr
    Sheets.Add After:=Sheets(Sheets.Count)
    OldName = ActiveCell.Worksheet.Name
    NewName = Range("Mgr_Name")
    Sheets(OldName).Name = NewName

GoSub CreateFilter
Next Mgr

Application.DisplayAlerts = True
Exit Sub


    Range("JOB_DATA").AdvancedFilter Action:=xlFilterCopy, _
        CriteriaRange:=Range("Crit1"), _
        CopyToRange:=Range("L2"), _

End Sub

Open in new window

Routine looks at all sheets in the Workbook, if it is one of the required sheets (Info, Data or Summary) it ignores it, otherwise it deletes it; clearing out the old filtered data.

It then refreshes the Pivot on Summary tab to refresh the list of Managers.

It then inserts a sheet for each Manager in the list and creates a filter on the data, copying the filtered data to cell L2 on the data tab. This is then Cut and Pasted to the sheet for that Manager.

NB For additional columns in your Data sheet, adjust the reference to cell L2 to a column that is sufficiently far away from your proper data to allow for some blank columns between your data and the extract destination. The Cut and Paste uses the CurrentRegion Selection to select the data, if there is no gap between the source data and the extract data it would select everything, source and extract. Use row 2 so that it does not impact the count in the JOB_DATA dynamic range.

I think that covers everything, any questions feel free to post as you come across them.

Rob H
LVL 33

Expert Comment

by:Rob Henson
ID: 39706276
Just had another read of your original question, do you need each sheet to be copied to a separate file so that you can e-mail just their file?

Can incorporate a few extra lines to do that if so required.

Rob H
LVL 33

Expert Comment

by:Rob Henson
ID: 39706332
In case you do need the above, in the script add these few lines:

1) At the very beginning of the script add one line:

SaveDir = Application.ActiveWorkbook.Path & "\Saved\"

Open in new window

This determines where to save the copied sheets, the current directory plus a sub-directory called "Saved"; the sub-directory will have to be created manually.

2) After "GoSub CreateFilter", line 29 of above snippet, add one line:

GoSub CreateWorkbook

Open in new window

3) After the CreateFilter SubRoutine, between lines 53 and 55 add the following snippet:

    SaveDate = Format(Date, "yyyymmdd")
    SaveName = NewName & "_" & SaveDate
    FullFileName = SaveDir & SaveName
    ActiveWorkbook.SaveAs _
        Filename:=FullFileName, _
        FileFormat:=xlOpenXMLWorkbook, _

Open in new window

This saves the copied sheet with the naming convention "ManagerName _ yyyymmdd.xlsx"

I have used the date format yyyymmdd so that when they are sorted by Filename in Windows Explorer, they appear in chronological order.

Rob H

Author Comment

ID: 39706345
That looks real good Rob.
Allow me some time to check into it.
You will hear from me tomorrow.
And yes different workbook is a great idea.

Have a very nice day (you made mine).

Author Closing Comment

ID: 39708313
Thanks. Much appreciated.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Excel compare strings 6 54
find and replace in column A across 75 csv books 8 31
Excel + CountIfs + two colums 5 39
Excel Index/Match issue 4 15
A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  ( Here (http…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …

734 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question