![]() |
![]() |
|
|||||||
| Excel Questions All Excel/VBA questions - formulas, macros, pivot tables, general help, etc. Please post to this forum in English only. |
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Join Date: Feb 2004
Posts: 210
|
Hy,
I was wondering if it is possible to format a part of text in the same cell, or it is better to cutt the string and put it into multiple cells... Thanks... Ps: would the text box be a good solution? |
|
|
|
|
|
#2 |
|
Join Date: Oct 2003
Location: Glasgow, Scotland
Posts: 1,482
|
You can do it via the Formula Bar, but that may not be very practical if you have a great deal of text in lots of cells. Works fine for a single cell - highlight the text and then format as usual.
Regards
__________________
Iain - XL2002 on Win XP - A Bank is a place that will lend you money if you can prove you don't need it. Member of ASAP :: Member of UNITE |
|
|
|
|
|
#3 |
|
Join Date: Feb 2004
Posts: 210
|
Hy,
Thx for the reply, What i want to do is search for a word in diffrent cells, and whenever i find this word i want it to be highlited... (in a VB code of course) |
|
|
|
|
|
#4 |
|
MrExcel MVP
Join Date: Mar 2004
Location: Oregon
Posts: 13,278
|
What's the word?
Is there a specific range of cells you are looking to find it in? It will also need to be straight text, not the result of a formula. |
|
|
|
|
|
#5 |
|
MrExcel MVP
Join Date: Feb 2002
Location: San Francisco, California USA
Posts: 9,626
|
The thing with this sort of request is, there are so many possibilities of what can be the case, it is hard for people who ask for this to pin down what they really want. Consider, assuming you want the word "word" to be highlighted:
- Should it only be "word"? - What about "Word"? - What about "WORD" - Should the "word" portion of "wordy" or "words" only be highlighted? Or ignored because it is part of a bigger word? - If ignored, then a consideration needs to be made for when / if it is found at the end of a sentence, and abutting a punctuation character, such as "That's the word.", or "Is that the word?" - What if there is more than one instance of that word in the cell? Highlight all that are found? Only the first instance? I'm not trying to bedevil you here, just suggesting you consider what you really want, from a one programmer's perspective. Keep in mind this is only possible with constants, not in cells containing formulas. If you select a range of cells, the following code will set in bold red font the first instance of the word "word" in any form it is found within the selected cells. I'll be off the board until Tuesday afternoon so if this is not all you want, perhaps someone else may assist. Then again, if it is what you want, then hey, cool. Sub Test1() Application.ScreenUpdating = False Dim cell As Range, Txt As String, TxtLen As Integer Txt = "word" TxtLen = Len(Txt) For Each cell In Selection.SpecialCells(2, 3) With cell Dim StrLoc As Integer On Error Resume Next StrLoc = Application.Search(Left(Txt, Len(Txt)), .Value) If Err.Number = 0 Then With .Characters(START:=StrLoc, Length:=TxtLen).Font .ColorIndex = 3 .Bold = True End With Else Err.Clear End If End With Next cell Application.ScreenUpdating = True End Sub
__________________
Tom Urtis |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|