+ Reply to Thread
Results 1 to 2 of 2

Macro to Create Pivot Table

  1. #1
    Registered User
    Join Date
    04-11-2016
    Location
    Cincinnati, OH
    MS-Off Ver
    2007
    Posts
    1

    Macro to Create Pivot Table

    Please Login or Register  to view this content.
    I have created a macro and the above line is adding pivot field to the data field (if I said that correctly) and it then need to do that 12 more times. It works just fine this week, but next week it will not function as the "03" "Min of 03" "04" "Min of 04" will be different week to week. I am wondering if there is a way to select these via a wildcard or another method that I do not need exact name of the field from the data?
    Last edited by Lumpy45247; 04-12-2016 at 12:51 PM. Reason: Mistakes

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

    Re: Macro to Create Pivot Table

    You can read this information from a named static range on the spreadsheet. Whether you enter the data in manually to these cells or you calculate them based on the date, I leave to you.

    The simplest way to make a named static range is to put the cursor in the cell and then in the name box (upper left) type in the name you want. So if you want to name cell B2 to First_Column, put the cursor in cell B2, then go to the name box (it probably says B2) and type in First_Column. Names have to start with a letter, cannot resolve to an existing cell reference such as END2, can't have spaces and the only punctuation allowed is the underscore.

    So say you name B2 to First_Column and B3 to Second_Column and you put 03 and 04 in them respectively (I advise formatting the column as text. Then your code becomes.
    Please Login or Register  to view this content.
    I don't think you'll have to add quotes around the values for the pivot fields. If you do something like PivotFields(Chr(34) & Col1 & Chr(34)) - where Chr(34) is ASCII for the double quote.
    One spreadsheet to rule them all. One spreadsheet to find them. One spreadsheet to bring them all and at corporate, bind them.

    A picture is worth a thousand words, but a sample spreadsheet is more likely to be worked on.

+ 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] Define variable in macro than calling that macro inside another macro
    By jakopak in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 08-21-2015, 10:58 AM
  2. Using a macro on workbook1 to create a button in wb2 and assigning macro "wb2!macro"
    By penfold1992 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 08-13-2014, 11:39 AM
  3. [SOLVED] Macro to show Which macro didnt work in a nested macro
    By akhileshgs in forum Excel Programming / VBA / Macros
    Replies: 14
    Last Post: 06-10-2013, 03:21 AM
  4. Perform macro "on open" specific file- store macro in Personal Macro Workbook?
    By thompssc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-17-2012, 12:38 PM
  5. lookup macro, solver macro, realtime macro
    By xelhelp in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 03-02-2011, 06:14 PM
  6. Cannot find macro error when running a macro from a macro in a diffrent workbook.
    By Acrobatic82 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-05-2010, 09:22 AM
  7. [SOLVED] Macro calling another Macro: "The macro 'Personal.xls!FindChar"
    By William Benson in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-07-2005, 09:05 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