+ Reply to Thread
Results 1 to 19 of 19

Pivot Table VBA Changing Data Range

  1. #1
    Registered User
    Join Date
    05-25-2012
    Location
    Northeast
    MS-Off Ver
    Excel 2003
    Posts
    14

    Pivot Table VBA Changing Data Range

    Good day,

    I'm working on a macro that will be taking data from some tables and putting it into a table, and then generating a pivot table from that data. Where i am having trouble is getting the pivot cache to accept my references. I have one main problem that I think is giving me a problem.

    It is grabbing the data from specific sheets and areas correctly, but the pivot cache is having an issue. I think that the issue here is that I need the range of the data to be flexible. It is defined by two variables (Top1 and Bottom1) to distinguish the x range for this particular set of data. I am having a hard time getting the cache to accept my grammar.

    I am not sure now to get it to be variable using the R1C1 formatting, but I am having a tough time getting it to accept it in absolute terms.

    Please Login or Register  to view this content.
    Dark Green is setting the ranges in another sheet to cut the right info and place it into my "Pivot Data" sheet
    Red is just pasting and formatting said data into the sheet I want to use to feed my pivot table
    black is the portion of the code that is defining the range of the data to be dragged into the pivot. I BELIEVE i need to come up with a way to incorporate this into the rest of my code, but that is only the best way I have come to do this kind of thing so far--recommendations are appreciated
    Green is my two thoughts as to how to do this but i keep getting a plethora of errors no matter what i try.

    Thanks all,
    ~Joe
    Last edited by jwh591; 06-12-2012 at 05:55 PM.

  2. #2
    Registered User
    Join Date
    05-25-2012
    Location
    Northeast
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Pivot Table VBA Changing Data Range

    Any thoughts??

  3. #3
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,265

    Re: Pivot Table VBA Changing Data Range

    Try something like this:
    Please Login or Register  to view this content.
    Remember what the dormouse said
    Feed your head

  4. #4
    Registered User
    Join Date
    05-25-2012
    Location
    Northeast
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Pivot Table VBA Changing Data Range

    Quote Originally Posted by romperstomper View Post
    Try something like this:
    Please Login or Register  to view this content.
    Thanks Romperstomper

    Ill have to plug this in in a little bit and see how I do

    `Joe

  5. #5
    Registered User
    Join Date
    05-25-2012
    Location
    Northeast
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Pivot Table VBA Changing Data Range

    Quote Originally Posted by romperstomper View Post
    Try something like this:
    Please Login or Register  to view this content.

    Having a very odd issue with the code: It doesn't paste the data from column I into the Pivot Data worksheet. It pastes the heading and the format of the cells (Bold borders) but no actual data.

    Trying a few different things but no positive results. I was using a hybrid of your code and what I had before to manipulate the data and it worked fine (i.e. I didn't really use "With" as I'm relatively unfamiliar with it. i ran into a problem because the portion of your code that generated the pivot table gave me an error so I tried running it with your code only and there is some issue with how it treats data in I. I looked and the data is all there and everything, kinda stuck.

    Thanks
    ~Joe

  6. #6
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,265

    Re: Pivot Table VBA Changing Data Range

    Is the data in column I formulas or values?

    By the way, there is no need to keep quoting my entire post back at me - it just makes the thread harder to read.

  7. #7
    Registered User
    Join Date
    05-25-2012
    Location
    Northeast
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Pivot Table VBA Changing Data Range

    Gotcha.
    Column I is values. EX:

    VF
    DF
    4H
    E7

  8. #8
    Registered User
    Join Date
    05-25-2012
    Location
    Northeast
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Pivot Table VBA Changing Data Range

    Gotcha.
    Column I is values. EX:

    VF
    DF
    4H
    E7

  9. #9
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,265

    Re: Pivot Table VBA Changing Data Range

    Can you post a workbook? I can't see any reason why that wouldn't work as it is.

  10. #10
    Registered User
    Join Date
    05-25-2012
    Location
    Northeast
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Pivot Table VBA Changing Data Range

    I'll try. Our systems are ricidulously firewalled.

  11. #11
    Registered User
    Join Date
    05-25-2012
    Location
    Northeast
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Pivot Table VBA Changing Data Range

    Yeah no luck there--can't upload even a text file.

    I just don't understand how it pastes the format and A1 but nothing else but other code I write with the same exact dataset has no problem with it...

  12. #12
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,265

    Re: Pivot Table VBA Changing Data Range

    Bit of a longshot but in the code you definitely have
    Please Login or Register  to view this content.
    with a period in front of the word Range and not just:
    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    05-25-2012
    Location
    Northeast
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Pivot Table VBA Changing Data Range

    yessir,

    I abandoned my own code to try to just nail down this issue and pasting exactly what you wrote into a module I am having this issue still..

  14. #14
    Registered User
    Join Date
    05-25-2012
    Location
    Northeast
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Pivot Table VBA Changing Data Range

    So I moved the code around and got it to work. I moved the A1 copy/paste command to the second "With"

    Please Login or Register  to view this content.
    Out of curiosity, what is the advantage to using "With" here??
    Also, why is the "." before the lines within a "With" necessary?

    Thanks,
    ~Joe

  15. #15
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,265

    Re: Pivot Table VBA Changing Data Range

    Sorry - I really should have spotted that!

    The With...End with holds a reference to an object so you don't have to refer to it explicitly when using several properties/methods of the same object. The period means that what follows belongs to the object specified in the With part.

  16. #16
    Registered User
    Join Date
    05-25-2012
    Location
    Northeast
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Pivot Table VBA Changing Data Range

    Thanks!

    The only part that still stumps me a bit is the fact that it did copy some of the info but not all of it--very weird.

    I'll keep going through. The rest of the macro involves setting up the data in such a way then inserting the results into another spreadsheet for calculation... I'll probably be back.

    Thanks again,
    ~Joe

  17. #17
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,265

    Re: Pivot Table VBA Changing Data Range

    The column I range references were being related back to the column Z reference, not the worksheet, so actually referred to a range 9 columns to the right of Z. That's what you fixed and I should have spotted!

  18. #18
    Registered User
    Join Date
    05-25-2012
    Location
    Northeast
    MS-Off Ver
    Excel 2003
    Posts
    14

    Re: Pivot Table VBA Changing Data Range

    Oooh. Gotcha. With can be tricky huh..

  19. #19
    Forum Expert romperstomper's Avatar
    Join Date
    08-13-2008
    Location
    East Sussex, UK
    MS-Off Ver
    365, varying versions/builds
    Posts
    21,265

    Re: Pivot Table VBA Changing Data Range

    Yeah - especially if you're hacking stuff around in a hurry without testing.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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