View Single Post
 
Old 05-18-2025, 04:01 PM
macropod's Avatar
macropod macropod is offline Windows 10 Office 2016
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

There is no VBA code in your document, so it's impossible to know exactly what your code is doing. It's not even obvious what your secondary table looks like before anything is selected from the dropdown.

That said, try the following code:
Code:
Private Sub Document_ContentControlOnExit(ByVal CCtrl As ContentControl, Cancel As Boolean)
Application.ScreenUpdating = False
Dim r As Long, i As Long
If CCtrl.ShowingPlaceholderText = True Then: i = 2: Else i = CCtrl.Range.Text + 2: End If
With ActiveDocument.Tables(2)
  For r = .Rows.Count To i Step -1: .Rows(r).Delete: Next
  For r = .Rows.Count + 1 To i - 1
    .Rows.Add: .Rows(r).Range.Font.Bold = False
    .Cell(r, 1).Range.Text = (r - 2) * 1000 & " - " & (r - 1) * 1000
    .Cell(r, 2).Range.Text = "1000": .Cell(r, 3).Range.Text = "0,00"
  Next
End With
Application.ScreenUpdating = True
End Sub
With this code, your second table need only have the heading row and you can change the dropdown selection at will to add/delete rows.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote