Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #1  
Old 02-18-2020, 08:48 PM
Jennifer Murphy's Avatar
Jennifer Murphy Jennifer Murphy is offline Macro to highlight alternating sections of a table Windows XP Macro to highlight alternating sections of a table Office 2007
Competent Performer
Macro to highlight alternating sections of a table
 
Join Date: Aug 2011
Location: Silicon Valley
Posts: 234
Jennifer Murphy is on a distinguished road
Default Macro to highlight alternating sections of a table

I have a table of results for a collection of experiments. Each experiment has a title and may be run multiple times with different criteria. When I sort the table by the title, I like to highlight every other set of results with a light blue background. This helps be focus on the results for each experiment.



I did this manually once. But now I have added some new experiments that sort between existing experiments. Unless I redo the entire list, I will have two consecutive sets with the same highlighting (blue or none).

I would like to write a macro to redo the highlighting every time I add a new experiment, but my skills with Word VBA is not good enough.

Can someone give me the initial outline of a macro that will loop through each line (row) of a table, examine the title field, and change the highlighting whenever the title changes?

Here's a rough outline of what I think the macro needs to do. The code in parens is what I don't know how to do.

Code:
Sub TableHiLite()  'Not sure if it needs parameters

Dim HiLite as boolean
HiLite = True
Dim Row as Integer
Dim NumRows as Integer
 NumRows = (number of rows in the table)
Dim TitleNext as String
Dim TitlePrev as String

For Row = 2 to NumRows
  TitleNext = (title text in this row)
  If TitleNext <> TitlePrev then HiLite = Not HiLite
  If HiLite then (set the highlight for this row to light blue)
  Else (set the highlight for this row to light none)
Next Row

End Sub
Thanks

PS: Ooops. I just realized that this should have gone into the VBA section. Maybe someone can move it. Sorry.
Reply With Quote
 



Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to highlight alternating sections of a table Macro to highlight a list of words bakerkr Word VBA 4 10-19-2017 02:23 PM
Macro to highlight alternating sections of a table Word 2010 VBA Print Macro - Specified Sections Benbon Word VBA 3 03-30-2017 02:31 PM
Macro to highlight alternating sections of a table Macro Question: Need help making a macro to highlight the first word in every sentence LadyAna Word 1 12-06-2014 10:39 PM
Macro to highlight alternating sections of a table Macro to highlight words bertietheblue Word VBA 9 07-01-2013 12:39 PM
find - reading highlight - highlight all / highlight doesn't stick when saved bobk544 Word 3 04-15-2009 03:31 PM

Other Forums: Access Forums

All times are GMT -7. The time now is 05:51 PM.


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