simmo said:
I have learnt a lot in the last few days, one of them being my
girlfriend is not very happy with me sitting if front of the PC all
day, the other is how fulfilling it is to slowly start to understand a
little more VB code. I appreciate all your help.
Do you write code for a living or is it a hobby. Some lovely photos of
Cyprus on your web page. I was based their for six months a few years
ago and have been back three times since on holiday.
Is it possible to ignore the merged cells in the search so the macro
will work. The only content in the rows with merged cells are titles
and don’t need to be searched.
Would It be ok to send you an email, my email address is
@@@@@@@ if not I understand you don’t know what type
of lunatic you might be communicating with on the internet, im just
interested to learn a bit more and would like to deal directly,
obviously for a price.
Thanks again
The following version will work even if the cells are merged, by processing
the adjacent cells separately but if any of the cells are vertically merged,
you will get some very odd results, as the merged cells in the 'row' will be
filled to produce 'battlements'
Sub Namesred15()
Dim x As Long
Dim oRng As Range
Dim arrU(6) As Variant
arrU(0) = "RECORD"
arrU(1) = "Y Age"
arrU(2) = "Arnold"
arrU(3) = "N Barras"
arrU(4) = " K Billing"
arrU(5) = "J Brady"
arrU(6) = "J Wood"
For x = 0 To UBound(arrU) 'test each variant in turn
Selection.HomeKey wdStory 'go to the start of the document
With Selection.Find
.ClearFormatting
.Replacement.ClearFormatting
While .Execute(findText:=arrU(x), _
MatchWildcards:=True)
Set oRng = Selection.Range 'mark the found text
If x = 0 Then 'Item is the first variant in the list
With oRng 'so make it bold and set the
'background of the cell to blue
.Font.Bold = True
.MoveEnd wdRow, 1 'Move end of range to
'end of row
.MoveStart wdRow, -1 'Move start of range to
'beginning of row
For i = 1 To .Cells.Count 'Count the cells
'in the row and process each of them to add
'blue shading
.Cells(i) _
.Shading.BackgroundPatternColor = _
wdColorLightBlue
Next i
.Collapse wdCollapseEnd
End With
Else 'Item is not the first
With oRng 'so colour it red
.Font.Color = wdColorRed
.Collapse wdCollapseEnd
End With
End If
Wend
End With
Next 'now look for the next string
End Sub
As you have visited my web site, you could have spotted that I am retired
and I frequent the Word forums and maintain the web site to keep my brain
working. The photographs on the web site are a reflection of the fact that I
live in Cyprus. If you are thinking of coming over for holiday this year,
the current value of the GB pound will make it an expensive visit
I do try and answer questions related to my web site from correspondents who
use the link on my home page with matters related to the web site, but I do
not offer private consultancy. If that is what you require, several of my
fellow Word MVPs scattered around the world will be happy to take your
money. And donations to my web site are always appreciated from those who
find the material there useful.
By frequenting this forum particularly - to which end you may find
http://www.gmayor.com/MSNews.htm a more practical means of accessing it -
you will learn far more about vba programming by experimenting and asking
questions when you get stuck. There are several people regularly
contributing here who are better programmers than I would ever try and claim
to be and few are the questions that go unanswered.
However you may find accessing this forum and the associated puzzle solving
somewhat addictive, so if you neglect that girlfriend, don't be too
surprised if she moves on
PS It is not a good idea to use a valid e-mail address in these forums - you
could end up with more than your share of spam as a result. If your ISP does
not offer spam filtering, see
http://www.gmayor.com/use_google_gmail_to_remove_spam.htm
--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>