ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Highlight found text string in cell? (https://www.excelbanter.com/excel-programming/300377-highlight-found-text-string-cell.html)

Ed[_18_]

Highlight found text string in cell?
 
Having gotten my "find this" macro going (big thanks to Chip Pearson!), I'm
now wondering if it is possible to highlight the text string when it's
found. I use an InputBox to get a text string, then use the string in
Set rngFound = Selection.Find(What:=MyTarget, _
MatchCase:=False)

I'm searching through a spreadsheet of test report information, such as
title, grouping, condition, subject, failures and modes, and so forth.
rngFound is set to columns A-U of one row at a time. The text string can be
any where in any cell in that range; if not, the entire row is hidden. If I
want to search for all reports on the "start" of various test procedures,
I'll not only get "Start of Cold Test", but "Starter Failed", and so forth.
If there was some way I could highlight my text string - maybe turn the
letters a different color or bold them or something - I could at a glance
tell if the string was found in a parameter meaningful to my search
(something I can't necessarily code in without a lot of extra stuff and
crossed-finger hoping the reports were written correctly!).

Is this easily possible?

Ed



Vasant Nanavati

Highlight found text string in cell?
 
Untested, but try:

If Not rngFound Is Nothing Then
rngFound.Characters(WorksheetFunction.Search(MyTar get, Range("A1")),
Len(MyTarget)).Font.Color = vbRed

--

Vasant

"Ed" wrote in message
...
Having gotten my "find this" macro going (big thanks to Chip Pearson!),

I'm
now wondering if it is possible to highlight the text string when it's
found. I use an InputBox to get a text string, then use the string in
Set rngFound = Selection.Find(What:=MyTarget, _
MatchCase:=False)

I'm searching through a spreadsheet of test report information, such as
title, grouping, condition, subject, failures and modes, and so forth.
rngFound is set to columns A-U of one row at a time. The text string can

be
any where in any cell in that range; if not, the entire row is hidden. If

I
want to search for all reports on the "start" of various test procedures,
I'll not only get "Start of Cold Test", but "Starter Failed", and so

forth.
If there was some way I could highlight my text string - maybe turn the
letters a different color or bold them or something - I could at a glance
tell if the string was found in a parameter meaningful to my search
(something I can't necessarily code in without a lot of extra stuff and
crossed-finger hoping the reports were written correctly!).

Is this easily possible?

Ed





Vasant Nanavati

Highlight found text string in cell?
 
Sorry, for:

Range("A1")

substitute:

rngFound.

--

Vasant

"Vasant Nanavati" <vasantn *AT* aol *DOT* com wrote in message
...
Untested, but try:

If Not rngFound Is Nothing Then
rngFound.Characters(WorksheetFunction.Search(MyTar get, Range("A1")),
Len(MyTarget)).Font.Color = vbRed

--

Vasant

"Ed" wrote in message
...
Having gotten my "find this" macro going (big thanks to Chip Pearson!),

I'm
now wondering if it is possible to highlight the text string when it's
found. I use an InputBox to get a text string, then use the string in
Set rngFound = Selection.Find(What:=MyTarget, _
MatchCase:=False)

I'm searching through a spreadsheet of test report information, such as
title, grouping, condition, subject, failures and modes, and so forth.
rngFound is set to columns A-U of one row at a time. The text string

can
be
any where in any cell in that range; if not, the entire row is hidden.

If
I
want to search for all reports on the "start" of various test

procedures,
I'll not only get "Start of Cold Test", but "Starter Failed", and so

forth.
If there was some way I could highlight my text string - maybe turn the
letters a different color or bold them or something - I could at a

glance
tell if the string was found in a parameter meaningful to my search
(something I can't necessarily code in without a lot of extra stuff and
crossed-finger hoping the reports were written correctly!).

Is this easily possible?

Ed







Tom Ogilvy

Highlight found text string in cell?
 
Sub AATester10()
Dim rngFound As Range
Dim MyTarget As String
MyTarget = "brown"
Set rngFound = Selection.Find(What:=MyTarget, _
MatchCase:=False)
If Not rngFound Is Nothing Then
iloc = InStr(1, rngFound, MyTarget, vbTextCompare)
rngFound.Characters(iloc, Len(MyTarget)).Font.Bold = True
End If
End Sub


--
Regards,
Tom Ogilvy




"Ed" wrote in message
...
Having gotten my "find this" macro going (big thanks to Chip Pearson!),

I'm
now wondering if it is possible to highlight the text string when it's
found. I use an InputBox to get a text string, then use the string in
Set rngFound = Selection.Find(What:=MyTarget, _
MatchCase:=False)

I'm searching through a spreadsheet of test report information, such as
title, grouping, condition, subject, failures and modes, and so forth.
rngFound is set to columns A-U of one row at a time. The text string can

be
any where in any cell in that range; if not, the entire row is hidden. If

I
want to search for all reports on the "start" of various test procedures,
I'll not only get "Start of Cold Test", but "Starter Failed", and so

forth.
If there was some way I could highlight my text string - maybe turn the
letters a different color or bold them or something - I could at a glance
tell if the string was found in a parameter meaningful to my search
(something I can't necessarily code in without a lot of extra stuff and
crossed-finger hoping the reports were written correctly!).

Is this easily possible?

Ed





Ed[_18_]

Highlight found text string in cell?
 
Thank you, Tom!
Ed

"Tom Ogilvy" wrote in message
...
Sub AATester10()
Dim rngFound As Range
Dim MyTarget As String
MyTarget = "brown"
Set rngFound = Selection.Find(What:=MyTarget, _
MatchCase:=False)
If Not rngFound Is Nothing Then
iloc = InStr(1, rngFound, MyTarget, vbTextCompare)
rngFound.Characters(iloc, Len(MyTarget)).Font.Bold = True
End If
End Sub


--
Regards,
Tom Ogilvy




"Ed" wrote in message
...
Having gotten my "find this" macro going (big thanks to Chip Pearson!),

I'm
now wondering if it is possible to highlight the text string when it's
found. I use an InputBox to get a text string, then use the string in
Set rngFound = Selection.Find(What:=MyTarget, _
MatchCase:=False)

I'm searching through a spreadsheet of test report information, such as
title, grouping, condition, subject, failures and modes, and so forth.
rngFound is set to columns A-U of one row at a time. The text string

can
be
any where in any cell in that range; if not, the entire row is hidden.

If
I
want to search for all reports on the "start" of various test

procedures,
I'll not only get "Start of Cold Test", but "Starter Failed", and so

forth.
If there was some way I could highlight my text string - maybe turn the
letters a different color or bold them or something - I could at a

glance
tell if the string was found in a parameter meaningful to my search
(something I can't necessarily code in without a lot of extra stuff and
crossed-finger hoping the reports were written correctly!).

Is this easily possible?

Ed








All times are GMT +1. The time now is 04:56 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com