Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Conditional formatting in a table based on cell content with a mac

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Gene-Salkovsky - 18 Mar 2008 15:35 GMT
I have a table that is 8 columns across and multiple rows.  The 2nd row is my
conditional.  If it is filled with "X" or "x" it will fomat the last 5
columns of that row in a dark gray background.  If it is Blank, it will not
do anything.  This needs to start on the first row and run until the end of
the document.  

I have been able to create the macro that turns the last 5 columns gray
(With my cursor in the 2nd cell) .  This will work for doing this one row at
a time, but I would prefer to do this all at once by clicking in row 1 / cell
2.  I found something else with FOR/NEXT, but not able to get it to work.  
This, in theory, is what I am looking for below.

[code]
Sub Macro3()

Dim TargetText As String
Dim oRow As Row

If Selection.Information(wdWithInTable) = False Then Exit Sub

TargetText = Chr(88) Or Chr(120)
For Each oRow In Selection.Tables(1).Rows
   If oRow.Cells(2).Range.Text = TargetText & vbCr & Chr(7) Then
       
   Selection.MoveRight Unit:=wdCharacter, Count:=8, Extend:=wdExtend
   Selection.Shading.Texture = wdTextureNone
   Selection.Shading.ForegroundPatternColor = wdColorAutomatic
   Selection.Shading.BackgroundPatternColor = wdColorGray15
   Selection.MoveLeft Unit:=wdCharacter, Count:=1
   Selection.MoveRight Unit:=wdCharacter, Count:=3, Extend:=wdExtend
   Selection.Shading.Texture = wdTextureNone
   Selection.Shading.ForegroundPatternColor = wdColorAutomatic
   Selection.Shading.BackgroundPatternColor = wdColorAutomatic
   Selection.MoveLeft Unit:=wdCharacter, Count:=1

Next oRow
End Sub
[/code]
Thank you.
Gene
Helmut Weber - 18 Mar 2008 16:55 GMT
Hi,

have a look at this one:

Sub Test4a()
Dim oRow As Row
Dim rTmp As Range
Dim sTmp As String
If Selection.Information(wdWithInTable) = False Then Exit Sub
Set rTmp = Selection.Range
' TargetText = Chr(88) Or Chr(120) ' type mismatch
For Each oRow In Selection.Tables(1).Rows
  sTmp = Left(oRow.Cells(2).Range.Text, 1)
  If sTmp = Chr(88) Or sTmp = Chr(120) Then ' watch out
     rTmp.Start = oRow.Cells(5).Range.Start
     rTmp.End = oRow.Cells(8).Range.End
     rTmp.Shading.Texture = wdTextureNone
     rTmp.Shading.ForegroundPatternColor = wdColorAutomatic
     rTmp.Shading.BackgroundPatternColor = wdColorGray15
  End If
Next oRow
End Sub

Note that this one doesn't work:
TargetText = Chr(88) Or Chr(120) ' type mismatch
Chr(88) Or Chr(120) returns a boolean
which can not be assigned to a string.

--

Greetings from Bavaria, Germany

Helmut Weber, MVP WordVBA

Vista Small Business, Office XP

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.