+ Reply to Thread
Results 1 to 12 of 12

how to convert Table to PivotTable with VBA

  1. #1
    Forum Contributor
    Join Date
    12-20-2016
    Location
    Uzbekistan
    MS-Off Ver
    2016
    Posts
    189

    Lightbulb how to convert Table to PivotTable with VBA

    Dear Excel Experts,

    Could You be kind to help to solve the riddle, how it is possible to convert Table into Pivot Table in new Sheet.
    Attaching Screenshot and file.Table to Pivot Table VBA.jpg
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: how to convert Table to PivotTable with VBA

    How about starting by recording a macro doing exactly that.
    Examine what was recorded and come back with any questions
    Click *Add Reputation to thank those who helped you. Ask if anything is not clear

  3. #3
    Forum Contributor
    Join Date
    12-20-2016
    Location
    Uzbekistan
    MS-Off Ver
    2016
    Posts
    189

    Re: how to convert Table to PivotTable with VBA

    Ok, i tried as You said. Error code 5....Attaching txt. I made comment where debugger showing error with "*" sign
    Attached Files Attached Files

  4. #4
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: how to convert Table to PivotTable with VBA

    Code below applies number format to pivot table cells (your code formatted worksheet columns)

    Your recorded code has been adapted to make it "general" (every version works)

    To see it work, open attached file and use shortcut {CTRL} K
    - three identical pivot tables are created

    Your workbook
    Insert the code in a Standard module in your workbook
    Select any cell inside your table before running the code

    VERSION1 is based on your recorded code
    Please Login or Register  to view this content.
    VERSION2 uses a variable for the new pivot table to remove clutter from the code
    Please Login or Register  to view this content.
    VERSION3 tidies things up a bit more
    Please Login or Register  to view this content.
    Attached Files Attached Files

  5. #5
    Forum Contributor
    Join Date
    12-20-2016
    Location
    Uzbekistan
    MS-Off Ver
    2016
    Posts
    189

    Re: how to convert Table to PivotTable with VBA

    Thank You kev_ that finally worked! But i wonder if it will work as my table located in other cells as in example from G1 to L1?

  6. #6
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: how to convert Table to PivotTable with VBA

    If you select any cell inside your table it should work regardless of where your table is placed

  7. #7
    Forum Contributor
    Join Date
    12-20-2016
    Location
    Uzbekistan
    MS-Off Ver
    2016
    Posts
    189

    Question Re: how to convert Table to PivotTable with VBA

    Kev, i just applied some before learned macroses, somehow code isn't working,

    Overall, the logic was to transform exported data to Table, then make a Pivot table From it,as we done.

    if it is not diff for You could please SHow me, my mistakes in code. Attaching to error txt.
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    12-20-2016
    Location
    Uzbekistan
    MS-Off Ver
    2016
    Posts
    189

    Re: how to convert Table to PivotTable with VBA

    People of the World, who can help me with my mistake in above Code?

  9. #9
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: how to convert Table to PivotTable with VBA

    transform exported data to Table, then make a Pivot table
    This code does that - run in attached workbook with {CTRL}K
    - user is asked by input box to select top left cell of the table range
    - Excel table is created (it is assumed that there are headers)
    - user asked if pivot table required
    - user asked to rename new pivot sheet
    - pivot table is created


    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by kev_; 04-13-2018 at 10:13 AM.

  10. #10
    Forum Contributor
    Join Date
    12-20-2016
    Location
    Uzbekistan
    MS-Off Ver
    2016
    Posts
    189

    Re: how to convert Table to PivotTable with VBA

    Kev Great thank you!, BUT it is not working with 1 st Transforming macros error....
    Attached Files Attached Files

  11. #11
    Forum Expert
    Join Date
    11-22-2016
    Location
    Cornwall,UK
    MS-Off Ver
    office 365
    Posts
    4,240

    Re: how to convert Table to PivotTable with VBA

    Please mark this thread as solved and begin a new thread - you are WAY beyond what you asked for in the original question

    Post#1
    how it is possible to convert Table into Pivot Table in new Sheet
    - post#4 provided the SOLUTION

    Post#7
    requirement increased
    Overall, the logic was to transform exported data to Table, then make a Pivot table From it,as we done
    - post #9 provided the SOLUTION

    Post#10
    requirement increased
    BUT it is not working with 1 st Transforming macro

    Please understand that saying that "something does not work" does not provide any of the information required to help you
    - you must explain what is not working, where the code is breaking down, what type of error you are getting etc


    On the new thread
    - explain FULLY what you are trying to achieve and NOT here is something that is broken!
    - if you have a macro that works that you want to join onto another macro, attach a workbook to the new thread with BOTH macros working separately
    Hopefully that will help you get the answers you want
    Last edited by kev_; 04-13-2018 at 11:49 AM.

  12. #12
    Forum Contributor
    Join Date
    12-20-2016
    Location
    Uzbekistan
    MS-Off Ver
    2016
    Posts
    189

    Re: how to convert Table to PivotTable with VBA

    ok kev, i will post a new question.

+ 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. [SOLVED] Convert to range for PivotTable
    By ImranBhatti in forum Excel Charting & Pivots
    Replies: 4
    Last Post: 10-06-2017, 12:48 PM
  2. Replies: 4
    Last Post: 11-29-2015, 07:20 AM
  3. Need serious help with Macro to convert CSV files to delimit and Pivottable.
    By boldingj10 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-27-2015, 03:29 PM
  4. Replies: 1
    Last Post: 09-11-2013, 02:27 PM
  5. Convert PivotTable to Normal Data Table
    By tunaaa in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-11-2011, 02:19 PM
  6. Convert PivotTable to MS Word Outline?
    By ComcoDG in forum Excel General
    Replies: 0
    Last Post: 03-26-2009, 04:44 PM
  7. [SOLVED] Convert PivotTable data into a worksheet list
    By sansk_23 in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 05-02-2005, 05:06 AM

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