Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 02-20-2020, 10:04 PM
macropod's Avatar
macropod macropod is offline Macro to highlight alternating sections of a table Windows 7 64bit Macro to highlight alternating sections of a table Office 2010 32bit
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

Quote:
Originally Posted by Jennifer Murphy View Post
My only reluctance is that means the code to read the data is in the macro in two places, which always opens up the possibility of them not being identical.
But you still need to initialise it somehow. And, of course, the whole point of the comparison is to change the highlight when they cease to be identical. Rather more complicated code could be used to do that within the loop, but the code would then run more slowly overall, which brings us to:
Quote:
Originally Posted by Jennifer Murphy View Post
The other solution that I have used is to check inside the loop if it's the first iteration, but that puts code inside the loop that is unnecessary after the first iteration, which I also don't like.
Nor do I.
Quote:
Originally Posted by Jennifer Murphy View Post
What if I change the datatype of the variable to Variant? Is there a value, like Null, that I can initialize it to that can never be a match for anything that could ever be in a Word table?
I can't see the point of that - one could just as easily initialise it as:


StrTitle = ""
(or not even bother initialising it), but then the shading would necessarily start at the second data row (undesirable), though the code could be modified to make it start at the first data row.
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote
  #2  
Old 02-20-2020, 10:51 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

Quote:
Originally Posted by macropod View Post
I can't see the point of that
The point is, as I said, initializing it to something that cannot be in the table. That way, the compare in the first pass through the loop will always fail, which is what I need.

But even if you cannot see a point, do you know if there is a Variant value that will fail a compare with any possible text value?

Quote:
- one could just as easily initialise it as:
StrTitle = ""
That fails if the data in the first row of the table is "". I admit that that is highly unlikely, but as Murphy (or someone) said, anything that can go wrong will go wrong.
Reply With Quote
Reply



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 08:22 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