View Single Post
  #9   Report Post  
Posted to microsoft.public.excel.programming
JLGWhiz JLGWhiz is offline
external usenet poster
 
Posts: 3,986
Default Search and change text color or style only

Sorry, I forgot to make it for variable length input. Try this.

Sub clrInput()
myInput = InputBox("Enter text to highlight", "Text")
With Worksheets(1).Range("B2")
.Characters(InStr(Range("B2"), myInput),
Len(myInput)).Font.ColorIndex = 3
End With
End Sub

"Tony S." wrote:

You're correct in the fact that I want to search existing text and change the
appearance of text that is typed in an input box. I do not want to replace
the value of the text. I thought there was a straight forward method to
accomplish this. Now it appears like it may be over my head. If you come
across anything I could try, I'd sure appreciate it if you passed it along.
Thanks for trying.
Tony

"JLGWhiz" wrote:

The macro colors whatever you enter into the input box. So if you type
something directly into a cell and then run the macro and enter something
different into the input box, it will replace whatever is in the cell with
what you have entered into the input box. Apparently, what you really are
asking about is how to replace or add text to text already in a cell and
identify the replaced or added text by font change.
That gets a little more complex, since it would require the user to make a
choice up front of which they were going to do, add or replace. But it could
be done with the same principle as the method using characters. You would
just have to write the code for either replace or concatenate. But I think
it can be done.

"Tony S." wrote:

JLGWhiz, thanks for your prompt reply. However when I type "The dog is large"
in cell B2 and run the macro, the entire sentenced is replaced by the word
"dog" in red. I would need to retain all the contents of the cell and just
bold and/or color the word "dog". Did I enter something wrong?
Tony

"JLGWhiz" wrote:

Sub clrinput()
myText = InputBox("Enter something", "Text")
With Sheets(1).Range("B2")
.Value = myText
.Characters(1, Len(myText)).Font.ColorIndex = 3
End With
End Sub


"Tony S." wrote:

Is it possible to use an input box (or other means of entry) to find and
change the properties of just the inputted text only within any column
selected? I have macros that change the cell color or all the text in the
cell, but I want to just highlight or bold or re-color the word of the text
I'm searching for. (i.e. If a cell contains "INSTALL FASTENERS WITH MPX 5-50
SEALANT PER BAC 4025 METHOD 3." I want to have the option to change the
appearance of just "MPX 5-50" or just "BAC 4025". I'm using Excel 2003.

I've used conditional formatting and been to Chip Pearson's site but can't
find the answer. Any help is greatly appreciated.
Tony