Share via

How to sum up values in a drop down list in Word

Anonymous
2022-08-30T15:16:10+00:00

Hi all,

I am creating a checklist in Word with a drop down list. The list consists of 5 options, with a value assigned to them, see the screenshot below.

Each point on the checklist is assigned to a category f.e. hygiene or comfort. I want the users of this form to be able to fill in an option (perfect, okay, not okay, not at all okay) and I want the form to sum up all the values ( 1 to 4) within a category. This way, the user has an idea on how much they score on each category.

Does someone know how to do this?

Thank you in advance!

Microsoft 365 and Office | Word | For business | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

5 answers

Sort by: Most helpful
  1. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2022-09-01T00:50:27+00:00

    If you title each of your content controls in the table according to their classification (i.e. ), and add text content controls using the same titles to each of the output lines at the end of the document, you can use a macro like:

    Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean) 
    
    Application.ScreenUpdating = False 
    
    Dim StrTitle As String, i As Long, j As Long, k As Long, r As Long 
    
    With CCtrl 
    
      If .Range.Information(wdWithInTable) = False Then Exit Sub 
    
      If ActiveDocument.Range(0, .Range.End).Tables.Count = 1 Then Exit Sub 
    
     StrTitle = .Title: i = 0: k = 0 
    
     With .Range.Tables(1) 
    
      For r = 1 To .Rows.Count 
    
        With .Cell(r, 3).Range.ContentControls(1) 
    
          If .Title = StrTitle Then 
    
            If .ShowingPlaceholderText = False Then 
    
              k = k + 4 
    
              For j = 1 To .DropdownListEntries.Count 
    
                If .DropdownListEntries(j).Text = .Range.Text Then 
    
                  i = i + .DropdownListEntries(j).Value: Exit For 
    
                End If 
    
              Next 
    
            End If 
    
          End If 
    
        End With 
    
      Next 
    
     End With 
    
    End With 
    
    With ActiveDocument 
    
      For r = .ContentControls.Count To 1 Step -1 
    
        With .ContentControls(r) 
    
          If .Range.Information(wdWithInTable) = True Then Exit For 
    
          If .Title = StrTitle Then 
    
            .LockContents = False 
    
            If i = 0 Then 
    
              .Range.Text = "" 
    
            Else 
    
              .Range.Text = i & " van een mogelijke " & k & " (" & Format(i / k, "0%") & ")" 
    
            End If 
    
            .LockContents = True 
    
            Exit For 
    
          End If 
    
        End With 
    
      Next 
    
    End With 
    
    Application.ScreenUpdating = True 
    
    End Sub
    

    The above macro should be placed in the 'ThisDocument' code module of your document or (preferably) its template.

    A fully-functional macro-enabled copy of your document is available here:

    https://1drv.ms/w/s!AiQxsUliBvlWcDo-END-KB8gt3Q?e=jEaQuN

    Was this answer helpful?

    1 person found this answer helpful.
    0 comments No comments
  2. Doug Robbins - MVP - Office Apps and Services 323K Reputation points MVP Volunteer Moderator
    2022-08-31T23:44:39+00:00

    You will need to save the file in a "macro-enabled" format, either docm or, most probably, dotm, and then insert Docvariable fields where the result is to be displayed

    and then, in the ThisDocument object of the file in the Visual Basic Editor, insert the following code:

    Private Sub Document_ContentControlOnExit(ByVal ContentControl As ContentControl, Cancel As Boolean)

    Dim Moederkoe As Long

    Dim Comfort As Long

    Dim Hygiene As Long

    Dim Arbeidsefficientie As Long

    Dim i As Long

    Moederkoe = 0

    Comfort = 0

    Hygiene = 0

    Arbeidsefficientie = 0

    With ActiveDocument.Tables(2)

    For i = 1 To .Rows.Count 
    
        If InStr(.Cell(i, 2).Range.Text, "Moederkoe") > 0 Then 
    
            Select Case .Cell(i, 3).Range.ContentControls(1).Range.Text 
    
                Case "Not at all okay" 
    
                    Moederkoe = Moederkoe + 1 
    
                Case "Not okay" 
    
                    Moederkoe = Moederkoe + 2 
    
                Case "Okay" 
    
                    Moederkoe = Moederkoe + 3 
    
                Case "Perfect" 
    
                    Moederkoe = Moederkoe + 1 
    
                Case Else 
    
                    Moederkoe = Moederkoe + 0 
    
            End Select 
    
        End If 
    
        If InStr(.Cell(i, 2).Range.Text, "Comfort") > 0 Then 
    
            Select Case .Cell(i, 3).Range.ContentControls(1).Range.Text 
    
                Case "Not at all okay" 
    
                    Comfort = Comfort + 1 
    
                Case "Not okay" 
    
                    Comfort = Comfort + 2 
    
                Case "Okay" 
    
                    Comfort = Comfort + 3 
    
                Case "Perfect" 
    
                    Comfort = Comfort + 1 
    
                Case Else 
    
                    Comfort = Comfort + 0 
    
            End Select 
    
        End If 
    
        If InStr(.Cell(i, 2).Range.Text, "Hygiene") > 0 Then 
    
            Select Case .Cell(i, 3).Range.ContentControls(1).Range.Text 
    
                Case "Not at all okay" 
    
                    Hygiene = Hygiene + 1 
    
                Case "Not okay" 
    
                    Hygiene = Hygiene + 2 
    
                Case "Okay" 
    
                    Hygiene = Hygiene + 3 
    
                Case "Perfect" 
    
                    Hygiene = Hygiene + 1 
    
                Case Else 
    
                    Hygiene = Hygiene + 0 
    
            End Select 
    
        End If 
    
        If InStr(.Cell(i, 2).Range.Text, "Arbeidsefficientie") > 0 Then 
    
            Select Case .Cell(i, 3).Range.ContentControls(1).Range.Text 
    
                Case "Not at all okay" 
    
                    Arbeidsefficientie = Arbeidsefficientie + 1 
    
                Case "Not okay" 
    
                    Arbeidsefficientie = Arbeidsefficientie + 2 
    
                Case "Okay" 
    
                    Arbeidsefficientie = Arbeidsefficientie + 3 
    
                Case "Perfect" 
    
                    Arbeidsefficientie = Arbeidsefficientie + 1 
    
                Case Else 
    
                    Arbeidsefficientie = Arbeidsefficientie + 0 
    
            End Select 
    
        End If 
    
    Next i 
    

    End With

    With ActiveDocument

    .Variables("Comfort").Value = Comfort 
    
    .Variables("Hygiene").Value = Hygiene 
    
    .Variables("Arbeidsefficientie").Value = Arbeidsefficientie 
    
    .Variables("Moederkoe").Value = Moederkoe 
    
    .Range.Fields.Update 
    

    End With

    End Sub

    NOTE: YOU WILL NEED TO MAKE ALL OF THE CHOICES IN THE DROPDOWNS THE SAME TO ELIMINATE THE DEVIATIONS THAT EXIST IN YOUR FILE AND, DEPENDING ON THE CHANGS TO THE CHOICES THAT YOU MAKE, YOU MAY NEED TO MODIFY THE ABOVE CODE SO THAT IT MATCHES THOSE CHOICES.

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2022-08-31T14:55:35+00:00

    Thank you for replying and helping me out. This is the link to my document: https://1drv.ms/w/s!Am7tAwy1mCVA5TEYER3iUiYtNwzd?e=Z65T8u

    Was this answer helpful?

    0 comments No comments
  4. Paul Edstein 82,861 Reputation points Volunteer Moderator
    2022-08-30T22:37:06+00:00

    For anyone to provide a meaningful solution to this - which will require the addition of some VBA code to your document - it would be helpful if you could upload your document to OneDrive, for example, and post a link to it here.

    Was this answer helpful?

    0 comments No comments
  5. Anonymous
    2022-08-30T17:04:28+00:00

    Dear Cecilia_214,

    Greetings! Thanks for posting in Microsoft Community.

    I understand that you have an issue with forms in Word. Could you share a sample files with us so we could test on our side and understand your requirement better? You could share the files with OneDrive sharelink with us.

    We look forward to your response. Thanks for your cooperation.

    Sincerely,

    Sean| Microsoft Community Moderator

    Was this answer helpful?

    0 comments No comments