+ Reply to Thread
Results 1 to 2 of 2

Copy filter data in another worksheet in form of PT

  1. #1
    Registered User
    Join Date
    05-28-2015
    Location
    California
    MS-Off Ver
    Microsoft office professional plus 2010
    Posts
    1

    Copy filter data in another worksheet in form of PT

    I have a raw data in "Data Entry" tab of a excel and i want to copy filtered data (Column 5: employee) to a new worksheet in the form of a Pivot table. I have written down the below code:
    Code (vb):

    Dim srcsht As Worksheet, dstsht As Worksheet
    Dim srcrng As Range

    Set srcsht = Sheets("Data Entry")
    Set srcrng = srcsht.Range("A:M")

    With srcsht
    'Create unique list of names from column E into Column Q
    .Range("E:E").AdvancedFilter Action:=xlFilterCopy, CriteriaRange:=.Range("E:E"), CopyToRange:=.Range("Q1"), Unique:=True
    lr = .Cells(Rows.Count, "Q").End(xlUp).Row

    For Each c In .Range("Q2:Q" & lr)
    Sheets.Add After:=ActiveWorkbook.Sheets(ActiveWorkbook.Sheets.Count)
    On Error Resume Next
    ActiveSheet.Name = c.Value
    Set dstsht = Sheets(c.Value)
    srcrng.AutoFilter Field:=5, Criteria1:=c.Value
    ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=srcrng.SpecialCells(xlCellTypeVisible).Copy, Version:=xlPivotTableVersion14).CreatePivotTable _
    TableDestination:=dstsht.Range("A1"), TableName:=c.Value, DefaultVersion _
    :=xlPivotTableVersion14

    This code is creating a new sheet with name of a filter but not creating pivot table. What is wrong in there and what needs to be changed?

    Any help will be very useful... Thanks in advance

  2. #2
    Forum Expert dflak's Avatar
    Join Date
    11-24-2015
    Location
    North Carolina
    MS-Off Ver
    365
    Posts
    7,920

    Re: Copy filter data in another worksheet in form of PT

    Two things: Wrap your code in code tags and provide a sample spreadsheet. Both will help us see the issue more clearly.

+ 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. Excel VBA Filter data and copy it to a different worksheet
    By ralucat23 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-16-2014, 05:28 PM
  2. Replies: 0
    Last Post: 10-08-2013, 02:58 PM
  3. filter data in one worksheet and copy into another
    By liv.waddington in forum Excel General
    Replies: 1
    Last Post: 10-06-2011, 02:55 PM
  4. Filter data and copy to another worksheet
    By electriceaze in forum Excel Formulas & Functions
    Replies: 5
    Last Post: 10-05-2011, 11:11 AM
  5. Consolidate, filter and copy data to another worksheet
    By Dunagh in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 07-08-2010, 07:39 PM
  6. Cant copy form data to worksheet, new row.
    By kwik98 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-25-2010, 08:40 PM
  7. Replies: 5
    Last Post: 03-18-2006, 08:45 AM

Tags for this Thread

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