View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
OssieMac OssieMac is offline
external usenet poster
 
Posts: 2,510
Default IMPORTANT!Conditionally formatting just 2 of many characters i

Hi Kay,

Do I interpret your comment to mean that " eg" can appear more than once in
the cells? If so, then the following will fix it although you probably do not
need it now if Gary's macro did the job.

In answer to your question "Is the coding the same for access?" I would say
that the answer is No. However, the principles of VBA remain the same and
there are a lot of similarities between them but for every similarity there
in another unique in each application.

Sub Format_Text()
Dim strToFind As String
Dim lngTofind As Long
Dim rngUsed As Range
Dim foundCell As Range
Dim startPos As Long
Dim firstAddress As String
Dim i As Long

strToFind = " eg" 'Set to required string

lngTofind = Len(strToFind)

With Sheets("Sheet1") 'Edit for your sheet name
Set rngUsed = .UsedRange
End With

With rngUsed
Set foundCell = .Find(What:=strToFind, _
LookIn:=xlFormulas, _
LookAt:=xlPart, _
SearchOrder:=xlByRows, _
SearchDirection:=xlNext, _
MatchCase:=False, _
SearchFormat:=False)

If Not foundCell Is Nothing Then
firstAddress = foundCell.Address

Do
For i = 1 To Len(foundCell)
startPos = InStr(i, foundCell, strToFind)
If startPos 0 Then
With foundCell.Characters(Start:=startPos, _
Length:=lngTofind).Font
.Color = vbRed
'.Bold = True 'Other formatting if required
End With
End If
Next i
Set foundCell = .FindNext(foundCell)
Loop While Not foundCell Is Nothing And _
foundCell.Address < firstAddress
End If
End With
End Sub


--
Regards,

OssieMac


"Kay" wrote:

Thanks to both who responded. I was actually able to get the test macro to
work, but the second macro seemed to find only the first t wo characters of a
string. But, since I am very weak in code, I probably did somsething wrong

Is the coding the same for access?

"Kay" wrote:

Hello,

Of course, all are aware that conditional formats are specific to a cell
using the format option in Excel. Can code be written that will search for
the characters " eg" with a space before and format only those characters?
The client is adamant and it takes forever to search for the characters and
then format manually.

Hope someone will help!

Thanks