A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Word » Formatting Long Documents
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Comparing cells, coloring differences



 
 
Thread Tools Display Modes
  #1  
Old March 4th, 2008, 12:19 AM posted to microsoft.public.word.formatting.longdocs
[email protected]
external usenet poster
 
Posts: 7
Default Comparing cells, coloring differences

Hopefully last question for a while -- I would like to compare
adjoining cells (B1 and C1, B2 and C2, etc.), and change the color of
the C cells which are not identical to their B counterparts.

It would save me an enormous amount of work, but unfortunately I'm not
quite at the point where I can work this sort of thing out by myself.
Any help would be greatly appreciated indeed!
  #2  
Old March 4th, 2008, 12:54 AM posted to microsoft.public.word.formatting.longdocs
Jay Freedman
external usenet poster
 
Posts: 9,488
Default Comparing cells, coloring differences

On Mon, 3 Mar 2008 16:19:17 -0800 (PST), wrote:

Hopefully last question for a while -- I would like to compare
adjoining cells (B1 and C1, B2 and C2, etc.), and change the color of
the C cells which are not identical to their B counterparts.

It would save me an enormous amount of work, but unfortunately I'm not
quite at the point where I can work this sort of thing out by myself.
Any help would be greatly appreciated indeed!


I think this handles all the contingencies, but I might have missed something.
Give it a whirl on some real tables and see if it needs any tweaks. Of course,
you can replace wdColorRed with any other color that appeals to you.

Sub ColorDifferences()
'compare adjoining cells (B1 and C1, B2 and C2, etc.),
'and change the color of the C cells which are not
'identical to their B counterparts

Dim oTbl As Table
Dim oRow As Row
Dim numRow As Long

If Not Selection.Information(wdWithInTable) Then
MsgBox "Please put the cursor in a table first."
Exit Sub
End If

Set oTbl = Selection.Tables(1)

If Not oTbl.Uniform Then
MsgBox "The macro can't deal with merged or split cells."
Exit Sub
End If

For numRow = 1 To oTbl.Rows.Count
Set oRow = oTbl.Rows(numRow)
With oRow
If Not .HeadingFormat Then
If .Cells(2).Range.Text .Cells(3).Range.Text Then
.Cells(3).Shading.ForegroundPatternColor = wdColorRed
End If
End If
End With
Next
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ:
http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so all may benefit.
  #3  
Old March 4th, 2008, 01:25 AM posted to microsoft.public.word.formatting.longdocs
[email protected]
external usenet poster
 
Posts: 7
Default Comparing cells, coloring differences

Thanks Jay! Unfortunately I'm getting a compile bug. (Probably I'm
doing something silly, or using the wrong version of Excel: Office XP
Professional, by the way.) The offending line is...

Dim oTbl As Table

.... and the error is ...

Compile Error:
User-defined type not defined.

  #5  
Old March 4th, 2008, 02:11 AM posted to microsoft.public.word.formatting.longdocs
[email protected]
external usenet poster
 
Posts: 7
Default Comparing cells, coloring differences

The problem is that you posted in the Word newsgroup, so I wrote a macro that
manipulates a Word table. (Yeah, maybe that is the wrong version of Excel. ;-)


Oh my goodness! My apologies!
  #6  
Old March 4th, 2008, 01:05 PM posted to microsoft.public.word.formatting.longdocs
DeanH
external usenet poster
 
Posts: 1,783
Default Comparing cells, coloring differences

In Excel you don't need a macro for this.
Use the Conditional Formatting, under Formatting menu.
Hope this helps.
DeanH

" wrote:

The problem is that you posted in the Word newsgroup, so I wrote a macro that
manipulates a Word table. (Yeah, maybe that is the wrong version of Excel. ;-)


Oh my goodness! My apologies!

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 05:17 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.