Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 10-24-2021, 12:40 PM
effimera effimera is offline Vba: Selecting table cells by fill colour Windows 10 Vba: Selecting table cells by fill colour Office 2019
Novice
Vba: Selecting table cells by fill colour
 
Join Date: Jun 2021
Posts: 8
effimera is on a distinguished road
Default Vba: Selecting table cells by fill colour

Hi there,



I was wondering if it is possible to create a macro that selects table cells with a specific fill colour.

In MS Word, I've got a table with 4 fill colours. The table extends over 300 pages, and I would need to select only two colours (if one at a time, that's OK, but the quicker the better), then to delete them.

I tried an alternative procedure by using Excel:
copy & paste > apply Filter by Colour > delete
However, this method is unsatisfactory in that Excel automatically sets the List and thus some unique numbers as General, resulting in a recalculation with entirely different numbers/codes (such as 8,15381E+11 instead of 815381020338 or 5.V instead of 5/5).

Therefore, I'd much prefer to use a macro in Word, if that's even possible.

Thanks a lot!
Reply With Quote
  #2  
Old 10-24-2021, 02:45 PM
Guessed's Avatar
Guessed Guessed is offline Vba: Selecting table cells by fill colour Windows 10 Vba: Selecting table cells by fill colour Office 2016
Expert
 
Join Date: Mar 2010
Location: Canberra/Melbourne Australia
Posts: 3,967
Guessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant futureGuessed has a brilliant future
Default

You need to post a sample document. Colours can be described in different ways (theme or RGB) so we need to see what you are looking at.

When you say your want cells deleted - do you mean delete the cell or remove the contents of the cell? If removing contents, do you want the cell recoloured afterwards.
__________________
Andrew Lockton
Chrysalis Design, Melbourne Australia
Reply With Quote
  #3  
Old 10-25-2021, 12:42 AM
effimera effimera is offline Vba: Selecting table cells by fill colour Windows 10 Vba: Selecting table cells by fill colour Office 2019
Novice
Vba: Selecting table cells by fill colour
 
Join Date: Jun 2021
Posts: 8
effimera is on a distinguished road
Default

I've added the Word file with a sample table.

What I meant was deleting the cells completely, i.e. not only the content but also the cell line.


So for example, I need to delete all grey and green cells, with the orange and white ones being untouched.



Thank you in advance.
Attached Files
File Type: docx AKR_1111111-990032.docx (14.8 KB, 10 views)
Reply With Quote
  #4  
Old 10-25-2021, 01:26 AM
gmayor's Avatar
gmayor gmayor is offline Vba: Selecting table cells by fill colour Windows 10 Vba: Selecting table cells by fill colour Office 2019
Expert
 
Join Date: Aug 2014
Posts: 4,101
gmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud ofgmayor has much to be proud of
Default

Try the following


Code:
Sub Macro1()
Dim i As Long
Dim oTable As Table
    For Each oTable In ActiveDocument.Tables
        For i = oTable.Rows.Count To 1 Step -1
            If oTable.Cell(i, 1).Shading.BackgroundPatternColor = &HCCFF00 Or _
               oTable.Cell(i, 1).Shading.BackgroundPatternColor = &HB2B2B2 Then
                oTable.Rows(i).Delete
            End If
        Next i
        DoEvents
    Next oTable
    Set oTable = Nothing
End Sub
__________________
Graham Mayor - MS MVP (Word) (2002-2019)
Visit my web site for more programming tips and ready made processes www.gmayor.com
Reply With Quote
  #5  
Old 10-25-2021, 12:26 PM
effimera effimera is offline Vba: Selecting table cells by fill colour Windows 10 Vba: Selecting table cells by fill colour Office 2019
Novice
Vba: Selecting table cells by fill colour
 
Join Date: Jun 2021
Posts: 8
effimera is on a distinguished road
Default It works!

It works perfectly!

Thank you so much
Reply With Quote
Reply

Tags
fill colour, table cell

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Vba: Selecting table cells by fill colour New table line has some cells fill colour change trevorc Excel 2 06-30-2021 12:27 PM
Text box fill colour changes when pasted to new file ParishPete Publisher 0 06-21-2019 12:47 AM
In Excel 2007-After Selecting Visibe Cells-How do I "Copy to Visible cells" Only mag Excel 0 10-28-2012 08:04 PM
How to fill a font colour to a particular data appear so many times in a column? PRADEEPB270 Excel 0 03-22-2012 02:04 AM
Accessibility Display & Colour Fill in Shapes thorn Office 0 08-11-2011 07:58 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 01:21 PM.


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