excel - Pivot table and Dates -


i newbie, , sort of enthusiastic learner, beginner making many mistakes. on pivot table picking 2 years worth of dates, keen choose first 2 recent dates, rather using slicer. have tried make little bit dynamic, getting error messages,

i trying have cells in spreadsheet date , 2 date, or code picks first 2 recent dates. want code work , pulling hair out, have few other pivot tables. every time put cell reference in between, dates keep getting coding errors.

i want pivot items more dynamic before, try add validation on date , date make lot more dynamic.

i want pivot items x first date , y second date referring 2 cells on sheet, can amend on sheet, , code picks first 2 recent dates.

sub dateslection ()   activesheet .pivottables("pivottable4").pivotfields("date")         .pivotitems("11/2/2016").visible = true         .pivotitems("10/26/2016").visible = true     end     end sub 

kind regards

ali

for dynamic filter this:

sub dateslection ()  dim startdate string dim enddate string  activesheet     'set date parameters in required date format      '- looks need      startdate = format(.range("a1").value, "mm/dd/yyyy")     enddate = format(.range("a2").value, "mm/dd/yyyy")      'clear existing filter , add new     .pivottables("pivottable4").pivotfields("date").clearlabelfilters     .pivottables("pivottable4").pivotfields("date").pivotfilters.add type _             :=xldatebetween, value1:=startdate, value2:=enddate end  end sub 

i understand want first 2 dates in pivot table? if can this:

activesheet.pivottables("pivottable4").pivotfields("date").pivotitems(1) activesheet.pivottables("pivottable4").pivotfields("date").pivotitems(2) 

to last 2 dates can do:

with activesheet.pivottables("pivottable4").pivotfields("date")     ptcount = .pivotitems.count     last = .pivotitems(ptcount)     secondlast = .pivotitems(ptcount - 1) end 

Comments

Popular posts from this blog

java - SSE Emitter : Manage timeouts and complete() -

jquery - uncaught exception: DataTables Editor - remote hosting of code not allowed -

java - How to resolve error - package com.squareup.okhttp3 doesn't exist? -