Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 05-18-2025, 01:01 PM
Slyraks Slyraks is offline How to format a word table based on a dropdown list value? Windows 10 How to format a word table based on a dropdown list value? Office 2013
Novice
How to format a word table based on a dropdown list value?
 
Join Date: May 2025
Posts: 1
Slyraks is on a distinguished road
Default How to format a word table based on a dropdown list value?

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
Reply With Quote
  #2  
Old 05-18-2025, 04:01 PM
macropod's Avatar
macropod macropod is offline How to format a word table based on a dropdown list value? Windows 10 How to format a word table based on a dropdown list value? 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
  #3  
Old 05-18-2025, 04:26 PM
macropod's Avatar
macropod macropod is offline How to format a word table based on a dropdown list value? Windows 10 How to format a word table based on a dropdown list value? 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

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]
Reply With Quote
Reply



Similar Threads
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
How to format a word table based on a dropdown list value? How to conditional format a table cell in word based on it's value. JulianS96 Word VBA 9 10-20-2021 02:25 AM
How to format a word table based on a dropdown list value? Hide table based on dropdown list 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
How to format a word table based on a dropdown list value? Auto populate a text field based on Content Control Dropdown List matthias92701 Word VBA 2 05-02-2019 03:54 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 09:12 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft