Need help with ChatGPT generated script to filter data

  • Hi All,

    It's been awhile since I posted. I've been working with ChatGPT to come up with what I thought was a relatively simple filtering script, however, have come to the point where the AI can't figure out the slicer error, and Im not great with the slicer I've come to the real experts to seek advice and guidance on the forum. Any help is appreciated.

    I'm trying to filter data for further analysis on an excel file that comes premade from other applications. The excel file has 4 slicers already at the top of the sheet, and a huge table with headers starting in cell A11 and the data in A12.

    The concept is that the script recognizes column's C,D,H as business line, market sectors, and project organization and filters the table data down to column C and D being BL004 and MS030, respectively.

    Afterwards, all existing slicers are removed and replaced with a single one that slices the remaining that data in column H "project org" so that it is able to be viewed and filters easily by the user.

    ChatGPT got me pretty far, but is failing on the line:

    Set slicerObj = slicerCache.Slicers.Add(ws, filterColumnH, Left:=10, Top:=10, Width:=200, Height:=100)

    with the error "Runtime error 5: invalid procedure call or argument"

    Any help would be appreciated.

    Code is here:

  • Remove the filterColumnH argument - that makes no sense (it's invalid as a Level argument, and that is only supported for OLAP sources anyway).

    Theory is when you know something, but it doesn’t work. Practice is when something works, but you don’t know why. Programmers combine theory and practice: nothing works and they don’t know why

  • In your specific case, the error seems to be coming from the line where you're trying to add a new slicer. The arguments you're passing to the Slicers.Add method might be causing the issue.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!