+ Reply to Thread
Results 1 to 9 of 9

Syntax Errors when building pivot table.

  1. #1
    Forum Contributor
    Join Date
    09-01-2008
    Location
    Australia
    Posts
    108

    Syntax Errors when building pivot table.

    Hi All,
    I am trying to use lastrow method to determine the lastrow used and then build a pivottable.
    However, got into syntax errors. Any help is appreciated.

    Please Login or Register  to view this content.
    What I am trying to do is for Row 6 and 7.

    Row 6
    "Sheet1!R2C2:R65000C34", Version:=xlPivotTableVersion12).CreatePivotTable _
    Change to
    "Sheet1!R2C2:"R"&Lastrow & C34", Version:=xlPivotTableVersion12).CreatePivotTable _

    Row 7
    TableDestination:="Sheet1!R30C3", TableName:="PivotTable2", _
    Change to
    TableDestination:="Sheet1!"R"&AddRow &C3", TableName:="PivotTable2", _

    Regards,
    Nironto
    Attached Files Attached Files

  2. #2
    Forum Guru HaHoBe's Avatar
    Join Date
    02-19-2005
    Location
    Hamburg, Germany
    MS-Off Ver
    work: 2016 on Win10 (notebook), private: 2019 on Win10 (desktop), 2019 on Win11 (notebook)
    Posts
    8,197

    Re: Syntax Errors when building pivot table.

    Hi, Nironto,

    maybe like
    Please Login or Register  to view this content.
    and
    Please Login or Register  to view this content.
    Ciao,
    Holger
    Use Code-Tags for showing your code: [code] Your Code here [/code]
    Please mark your question Solved if there has been offered a solution that works fine for you

  3. #3
    Forum Expert Mordred's Avatar
    Join Date
    07-06-2010
    Location
    Winnipeg, Canada
    MS-Off Ver
    2007, 2010
    Posts
    2,787

    Re: Syntax Errors when building pivot table.

    I haven't tested this but declaring all variables, including using a sheet variable and then using them may help.
    Please Login or Register  to view this content.
    Notice the
    Please Login or Register  to view this content.
    which explicitly states that the cell is in Sheet 1. Again, I don't know exactly what you want to do but there are no more syntax errors with what I did.

    Cheers!
    If you're happy with someone's help, click that little star at the bottom left of their post to give them Reps.

    ---Keep on Coding in the Free World---

  4. #4
    Forum Contributor
    Join Date
    09-01-2008
    Location
    Australia
    Posts
    108

    Re: Syntax Errors when building pivot table.

    Hi HaHoBe,
    Changing the rows as you instructed does not work as the row 5-8 is one whole.

    Hi Mordred,
    I have the excel book working already. But instead of hardcoding the row no. I want it to be flexible based on the no. of rows.
    So if i tried using the declared variables, it will have syntax error.

    You may try out on the attachment.

    e.g. row 7
    TableDestination:="Sheet1!R30C3", TableName:="PivotTable2", _
    Change to
    TableDestination:="Sheet1!"R"&AddRow &C3", TableName:="PivotTable2", _

    Regards,
    Nironto

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Syntax Errors when building pivot table.

    Hi nironto,

    Your question sounds like you want to refresh and rebuild a Pivot Table whenever there is a change to the data. That can be done using a Dynamic Named Range (DNR) and event code. See the attached that shows an example of this.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  6. #6
    Forum Contributor
    Join Date
    09-01-2008
    Location
    Australia
    Posts
    108

    Re: Syntax Errors when building pivot table.

    Thanks MarvinP,
    What I want to do is quite similar to yours.

    What happens is that rows may get added/ updated from time to time. (They are refreshed via odbc).
    And when so, the last row may then be changed from row no. 19 to row 50 etc.

    Your pivot is on the right hand side. I want the pivot to be at the bottom. ( 3 rows down from the last row.)

    (Thus Bottom instead of right). My pivot is working if on the right.
    See what happens is that if is fixed at row 30 Column 3, then i will have issues when records are more than 30.

    Please Login or Register  to view this content.

    Regards,
    Nironto

  7. #7
    Forum Contributor
    Join Date
    09-01-2008
    Location
    Australia
    Posts
    108

    Re: Syntax Errors when building pivot table.

    Hi All,
    To better explain my point.
    I had modified the excel sheet to have the pivot included.

    My issue is not about the pivot table. ( which is already working).
    My pain is that now the rows are e.g. 19. And the pivottable script is fixed at row 30.

    If i simulate the case where i have more than 30 rows. ( Which you can just add data or simply drag down to row more than 30.), then you get data truncated issue because the position is fixed at row 30.
    To test,
    delete the pivot table, add in more rows then click on the macro button.

    What i want is to have more control that based on last row + 3 which can be done if this syntax error is solved.



    Please Login or Register  to view this content.
    The above is working (but is fixed position at Row 30). But I want to change to using the variables as below.

    Row 6
    "Sheet1!R2C2:R65000C34", Version:=xlPivotTableVersion12).CreatePivotTable _
    Change to
    "Sheet1!R2C2:"R"&Lastrow & C34", Version:=xlPivotTableVersion12).CreatePivotTable _

    Row 7
    TableDestination:="Sheet1!R30C3", TableName:="PivotTable2", _
    Change to
    TableDestination:="Sheet1!"R"&AddRow &C3", TableName:="PivotTable2",

    Regards,
    Nironto
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    09-01-2008
    Location
    Australia
    Posts
    108

    Re: Syntax Errors when building pivot table.

    Hi All,
    I managed to find a solution.

    For the benefit of others who might have the same issue,
    I use the method of declaring another variable as string, e.g. LastRow1

    LastRow1 = "Checkout!R2C2:R" & LastRow & "C34", then input that as a value into the entire formula.

    Regards,
    Nironto

  9. #9
    Registered User
    Join Date
    07-29-2015
    Location
    MY
    MS-Off Ver
    office 2010
    Posts
    15

    Re: Syntax Errors when building pivot table.

    Hi,
    Can you please post here full code? I need it for reference as i facing the same problem as well.

+ 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