1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Change font color and italicized including brackets.

Discussion in 'Business Applications' started by sukisuki, Jan 7, 2013.

Thread Status:
Not open for further replies.
Advertisement
  1. sukisuki

    sukisuki Thread Starter

    Joined:
    Jan 7, 2013
    Messages:
    9
    Happy New Year to all.

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

    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. I'm using Excel 2007

    Hoping someone could rewrite the formula for me, I need it very importantly.

    Thank you very much.

    Here's the formula:

    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
     
  2. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    Please post a sample workbook showing your data layout.


    Rollin
     
  3. sukisuki

    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
     
  4. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    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
     
  5. sukisuki

    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
     
  6. Rollin_Again

    Rollin_Again

    Joined:
    Sep 4, 2003
    Messages:
    4,912
    Just change these two lines

    Remove the +1 and -1 at the end of each line so that they appear as


    Rollin
     
  7. sukisuki

    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
     
  8. Sponsor

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 733,556 other people just like you!

Loading...
Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/1084141

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice