![]() |
#1
|
|||
|
|||
![]()
Hi there,
I'm trying to update the values and formatting of a table based on a drop-down list So far, I've followed the steps in this post to change the values but I don't know how to delete the rows I don't need based on the type of table that needs to be displayed Examples of what I want to do - RangeVBATest.docx |
#2
|
||||
|
||||
![]()
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
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
#3
|
||||
|
||||
![]()
Cross-posted at: MS Answers
For cross-posting etiquette, please read: http://www.excelguru.ca/content.php?184
__________________
Cheers, Paul Edstein [Fmr MS MVP - Word] |
![]() |
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
How to conditionally format a cell in a table in MS Word based on a percentage range | Kiwi971 | Word | 1 | 10-02-2022 07:07 AM |
![]() |
JulianS96 | Word VBA | 9 | 10-20-2021 02:25 AM |
![]() |
lburch | Word Tables | 7 | 03-12-2021 02:51 PM |
Text based on selection of dropdown list | cloud67 | Word VBA | 2 | 08-09-2019 06:46 AM |
![]() |
matthias92701 | Word VBA | 2 | 05-02-2019 03:54 PM |