• Table calculations

    Author
    Topic
    #508111

    Hi
    Win 10 Office 365

    I am wanting to create a table that adds columns C & D and then in column H multiplies the result, column E by data in column G. I wish it copy down automatically when I add a new row below.

    cheers

    Viewing 6 reply threads
    Author
    Replies
    • #1590370

      To see how to do this and a wide range of other calculations in Word, check out my Microsoft Word Field Maths Tutorial, in the ‘Sticky’ thread at the top of this forum:
      http://windowssecrets.com/forums/showthread//154369-Microsoft-Word-Field-Maths-Tutorial
      Alternatively, use filling-in-forms protection and a macro. See, for example:

      Adding a new row to a table in a document with formfields:
      http://www.msofficeforums.com/word-vba/13955-macro-add-row-table-word-form.html#post38312

      Adding a new row to a table in a document with content controls:
      http://www.msofficeforums.com/word-vba/13955-macro-add-row-table-word-form.html#post38461

      If none of those options suit your needs, consider using an embedded Excel worksheet.

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

      • #1591432

        46738-Hazard-Identification46737-codePaul
        I have entered the field code using Ctrl F9 as follows

        46737-code

        In column H I wish to calculate E * G and then add a new row if required

        • #1591460

          You appear not to have taken account of the ‘Note’ to the Relative Referencing in Tables topic. You need to make the modifications described there, since your data don’t start on the first row of the table.

          Furthermore, your field braces are for the most part typed; you can’t do that – they must be created in pairs via Ctrl-F9 or via Insert|Quick Parts|Field.

          Cheers,
          Paul Edstein
          [Fmr MS MVP - Word]

    • #1591517

      Paul this thing is doing my head in!
      I can’t seem to get the row add function to activate when I add a new row.46749-Hazard-Identification

    • #1591519

      Since you’re using content controls, not formfields, you might get better results if you use a macro that works with content controls…
      See, for example: http://www.msofficeforums.com/word-vba/27809-code-add-new-row-table.html#post87989

      And, since you’re using macros, you may as well replace the field coding with macro coding that does the same job.

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

      • #1591521

        Paul
        For the life in me I cannot figure how to create the “on-exit” function for the content control. I know in older versions it was in the properties

    • #1591523

      That’s because there isn’t one – content controls use an event, for which the code goes in the ‘ThisDocument’ code module.

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

      • #1591597

        Paul
        I thought I had this sorted but for some reason it just doesn’t want to behave!
        46760-Hazard-Identification-2

        • #1591610

          I thought I had this sorted but for some reason it just doesn’t want to behave!

          Won’t behave in what sense?

          Cheers,
          Paul Edstein
          [Fmr MS MVP - Word]

          • #1591647

            The fields are not calculating as required despite adding this code
            ‘Update the bookmarked range
            .Bookmarks.Add Name:=StrBkMk, Range:=Selection.Tables(1).Range
            .Fields.Update

            Cannot figure this out as they are very basic calcs C*D & E*G

          • #1591718

            Paul
            In the attached I believe the code for the fields is correct and input using Ctrl F9 for all brackets. However, When I select a value in cells C & D it fails to calculate in cell E. Similarly for cell H which is also giving a Syntax error message when the code is identical to that in cell E.

            46760-Hazard-Identification-2
            Can you help?

    • #1591992

      Try the attached.

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

      • #1592030

        Paul
        Looks really good but the macro to insert a new row only fires for the first instance of inserting a new row

    • #1592073

      Change:
      If .Range.InRange(ActiveDocument.Bookmarks(StrBkMk).Range) = False Then Exit Sub
      to:
      If .Range.InRange(ActiveDocument.Bookmarks(StrBkMk).Range.Tables(1).Range) = False Then Exit Sub

      Cheers,
      Paul Edstein
      [Fmr MS MVP - Word]

    • #1592090

      Yep
      That did it. I thought it must have been a range issue
      Thanks for all your help

    Viewing 6 reply threads
    Reply To: Table calculations

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: