Change font color and italicized including brackets.

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

sukisuki

Thread Starter
Joined
Jan 7, 2013
Messages
9
[FONT=&quot]Happy New Year to all.[/FONT]

[FONT=&quot]I'm new here, and this is about Rollin_Again answer to Bibleuser question last July 27, 2012 [/FONT]([FONT=&quot]Replace contents in brackets with Italicized words and certain font color).[/FONT]

[FONT=&quot]The formula works to me but, when I run it, it takes away the brackets (in my case parentheses). What I want is change the font color and italicized including the brackets, so the brackets stay.[/FONT] I'm using Excel 2007

[FONT=&quot]Hoping someone could rewrite the formula for me, I need it very importantly.[/FONT]

[FONT=&quot]Thank you very much.

Here's the formula:

[/FONT]
Sub FindBrackets()

Set vFound = Cells.Find(What:="[*]", _
After:=ActiveCell, LookAt:=xlPart, SearchOrder:=xlByRows, _
SearchDirection:=xlNext, MatchCase:=False, SearchFormat:=False)

If Not vFound Is Nothing Then
Do
Call FormatCell(vFound.Address)
Set vFound = Cells.FindNext(vFound)
Loop Until vFound Is Nothing
Else
MsgBox ("Not Found")
End If

End Sub




Sub FormatCell(vAddress As String)

Dim aArray() As String

vCount = 0

Do While InStr(1, Range(vAddress).Value, "[") > 0 Or InStr(1, Range(vAddress).Value, "]") > 0

ReDim Preserve aArray(vCount)

vStart = InStr(1, Range(vAddress).Value, "[") - 1
vEnd = InStr(1, Range(vAddress).Value, "]") - 1

Range(vAddress).Value = Replace(Range(vAddress).Value, "[", "", , 1)
Range(vAddress).Value = Replace(Range(vAddress).Value, "]", "", , 1)

aArray(vCount) = vStart & "," & vEnd

vCount = vCount + 1

Loop

For i = 0 To UBound(aArray)
vStart = CInt(Mid(aArray(i), 1, InStr(1, aArray(i), ",") - 1))
vEnd = CInt(Mid(aArray(i), InStr(1, aArray(i), ",") + 1))

Range(vAddress).Characters(Start:=vStart, Length:=(vEnd - vStart + 1)).Font.Color = -16776961
Range(vAddress).Characters(Start:=vStart, Length:=(vEnd - vStart + 1)).Font.FontStyle = "Italic"

Next i

End Sub
 

sukisuki

Thread Starter
Joined
Jan 7, 2013
Messages
9
Hi Rollin_Again,

Thank you very much on replying to my post.
Your formula works good, it change the font color and italicized content in the brackets but it deleted the brackets.

What I want is change the font color and italicized content in the brackets and also the brackets, don't delete the brackets. (in my case parentheses)

THIS IS THE SAMPLE OF MY WORKBOOK

My original entry:
Text text text text (to replace)
Text (to replace) text text text text
Text text (to replace) text text
Text text text text text text
Text text text (to replace)

What I want is this:
Text text text text (to replace)
Text (to replace) text text text text
Text text (to replace) text text
Text text text text text text
Text text text (to replace)

Again thank you very much Sir.

Sukisuki
 
Joined
Sep 4, 2003
Messages
4,916
I think this modified code should do the trick

Code:
Sub FindParentheses()

Set vFound = Cells.Find(What:="(*)", MatchCase:=False)

If Not vFound Is Nothing Then
vStartCell = vFound.Address
Do
Call FormatCell(vFound.Address)
Set vFound = Cells.FindNext(vFound)
Loop Until vFound.Address = vStartCell
Else
MsgBox ("Not Found")
End If

End Sub


Sub FormatCell(vAddress As String)

Dim aArray() As String

vCount = 0

Do While InStr(1, Range(vAddress).Value, "(") > 0 Or InStr(1, Range(vAddress).Value, ")") > 0

ReDim Preserve aArray(vCount)

vStart = InStr(1, Range(vAddress).Value, "(") + 1
vEnd = InStr(1, Range(vAddress).Value, ")") - 1

Range(vAddress).Value = Replace(Range(vAddress).Value, "(", "[", , 1)
Range(vAddress).Value = Replace(Range(vAddress).Value, ")", "]", , 1)

aArray(vCount) = vStart & "," & vEnd

vCount = vCount + 1

Loop

Range(vAddress).Value = Replace(Range(vAddress).Value, "[", "(")
Range(vAddress).Value = Replace(Range(vAddress).Value, "]", ")")

For i = 0 To UBound(aArray)
vStart = CInt(Mid(aArray(i), 1, InStr(1, aArray(i), ",") - 1))
vEnd = CInt(Mid(aArray(i), InStr(1, aArray(i), ",") + 1))

Range(vAddress).Characters(Start:=vStart, Length:=(vEnd - vStart + 1)).Font.Color = -16776961
Range(vAddress).Characters(Start:=vStart, Length:=(vEnd - vStart + 1)).Font.FontStyle = "Italic"

Next i

End Sub
Rollin
 

sukisuki

Thread Starter
Joined
Jan 7, 2013
Messages
9
Hi Rollin,

Appreciate a lot your help. In any way you could visit my place, Aruba, I owe you a treat.

The modified formula works, I can use it.

I don't know if there's a way we can also make the "parentheses" same font color and italicized as the contents.

Your modified formula do this:
Text text text (replaced text) text

What I want is this:
Text text text (replaced text) text

Here it replaced the content and the parentheses.

Anyway, thank you thank you thank you very much.

Sukisuki
 
Joined
Sep 4, 2003
Messages
4,916
Just change these two lines

vStart = InStr(1, Range(vAddress).Value, "(") + 1
vEnd = InStr(1, Range(vAddress).Value, ")") - 1
Remove the +1 and -1 at the end of each line so that they appear as

vStart = InStr(1, Range(vAddress).Value, "(")
vEnd = InStr(1, Range(vAddress).Value, ")")

Rollin
 

sukisuki

Thread Starter
Joined
Jan 7, 2013
Messages
9
Hi Rollin,

Thank you very much. You're so kind.
It's perfectly works this time.

Sincerely,
Sukisuki[FONT=&quot][/FONT]
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top