Viewing 9 posts - 1 through 9 (of 9 total)
  • Excel, VBA and Pivot Tables. Karmic cash-in of help required
  • Stoner
    Free Member

    VBA and me dont get on. Never needed to do more than smash a macro up a bit.
    A colleague has a VBA query which I cant fix, and well, frankly she's pretty so come on guys time to help ol' Stoner out for a change 🙂

    can some one compile me some code that sets the filter field of the last column in a pivot table to <>0. The pivot table, when generated, could have any number of columns in it, but the last one (whatever number field it is) should always be set to <>0

    thinking Dim'ing "last column" as columns counted in the pivot table and then set field=last column, but havent a clue on the syntax.

    cheers guys.

    soma_rich
    Free Member

    This might help. It returns you the last cell for a sheet. You can then set it by saying your variable.value= "<>0"

    Public Function LastCol(Optional ByVal sSheet As String = "") As String
    'FIND THE LAST COLUMN FOR first ROW IN THE SUPPLIED SHEET
    ThisWorkbook.Worksheets(sSheet).Activate

    LastRow = Range("$IV$2").End(xlToLeft).Row

    ThisWorkbook.Worksheets("Sheet1").Activate

    End Function

    Stoner
    Free Member

    cheers samuri, but you're going to have to wind the dial further back towards "stupid" for me.

    Can you take me through dim the field number from that bit above and then using that dim in the pivot table filter command…

    I really am crap at VBA 🙁

    soma_rich
    Free Member

    Right You need to get my name right first!

    sub bob()
    dim fred as string

    fred =LastCol("your sheet name here")
    Range(fred&"your row number here").Value = "<>0"
    end sub
    Public Function LastCol(Optional ByVal sSheet As String = "") As String
    'FIND THE LAST COLUMN FOR first ROW IN THE SUPPLIED SHEET
    ThisWorkbook.Worksheets(sSheet).Activate

    LastRow = Range("$IV$2").End(xlToLeft).Column

    ThisWorkbook.Worksheets("Sheet1").Activate

    End Function

    You will still need an event to fire this or a button or something.. Samuari indeed *walks off shaking head*

    Stoner
    Free Member

    doh, sorry rich 😉

    thanks for that.
    although embedding a chippy, lippy cockney in my code goes against the grain a little 🙂

    shall go and try it out. will let you know if I die in a ball of runtime errors and flaming ostriches.

    mrmo
    Free Member

    if i wasn't having to suffer a Holiday, i could be a bit more helpful, i don't even have a copy of Excel.

    I did something similar, i think it used the Pivottable.filter type of syntax.

    If you do something similar to what you want too, but do it whilst recording a macro then hack the code to get it to do what you want in the real case.

    Stoner
    Free Member

    in the end we just used a filter outside of the pivot table.

    Ill come back to it some time and tidy it up. I really should get to grips with VBA but it goes against my declaration not to learn anything new since 2003.

    acjim
    Free Member

    Stoner; I'm interested in this (bad I know) but don't really get what you mean by setting a pivot table column (row field? grouping value?). If you want to send me an example file I'll have a crack at it for you.

    jimjamesjamesh (at) googlemail.com

Viewing 9 posts - 1 through 9 (of 9 total)

The topic ‘Excel, VBA and Pivot Tables. Karmic cash-in of help required’ is closed to new replies.