Help With Pivot Tables and Pivot Fields

onelifenoregret

New Member
Joined
Sep 13, 2013
Messages
13
Let me preface this by saying that I am extremely new to VBA. I'm trying to automate tasks in Pivot Tables like setting date ranges so that instead of having to drill down through all of the menus I can just hit a button and it does it. I was using a Worksheet full of formulas before but I'm trying to get away from that. I need to sort date ranges from Thursday morning to Wednesday night as well as first to last day of the month. I was using the formula "=TEXT((TODAY()+(7-(N(WEEKDAY(TODAY(),14))))),"mm/dd/yy")" to get my dates, that formula returns 05/13/15 I would then concatenate and use left mid and right to turn that into [Dates].[Date].&[2015-05-13T00:00:00] etc. I'm sure I was not being efficient, I know some stuff about excel but not enough to make me efficient or really all that good. With a PivotField like that above my code would then look like
Code:
Sub currentweek()
' macro to return the current week last Thursday to this Wednesday
    Dim pt As PivotTable
    Set pt = ActiveSheet.PivotTables("PivotTable1")
    Dim dateArray As Variant
    dateArray = Application.Transpose(Range("AB2:AB8").Value)
    On Error Resume Next
    pt.CubeFields(1).EnableMultiplePageItems = _
        True
    pt.PivotFields("[Dates].[Date].[Date]"). _
        VisibleItemsList = dateArray
End Sub
My questions are.... is there a thorough tutorial or walkthrough on how to use pivottables pivotfields cubefields etc. What is the easiest way to get those date ranges, and exactly how much of my life am I wasting by doing things the long hard way using fifty cells with fifty formulas to get one output?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top