Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Got an excel spreadsheet being used for some text content (I know, I know), but I'm wondering if anyone would know how to highlight specific text inside of a cell contained within brackets.

Cell would contain "Text goes here [bracketed red text] and so on and so on" with the "[bracketed red text]" a red color. Any help would be appreicated!

share|improve this question
3  
I think the only way you'll achieve this is with macros. I'll see what I can work out if I get a chance. –  Hand-E-Food Aug 9 '11 at 22:50

1 Answer 1

You need to create a macro. In Excel 2010, press View, Macros, View Macros. Type the name "Dummy" and press Create. In the new window that appears, look at the Project pane on the left. Double-click the sheet you want to apply the formatting to. Copy and paste the following code.

Private Sub Worksheet_Change(ByVal Target As Range)
    Dim Text As String
    Dim Index1 As Long
    Dim Index2 As Long
    Text = Target.Text
    Index2 = 1
    Do
        Index1 = InStr(Index2, Text, "[")
        If Index1 = 0 Then Exit Do
        Index2 = InStr(Index1, Text, "]")
        If Index2 = 0 Then Exit Do
        Target.Characters(Index1, Index2 - Index1 + 1).Font.Color = &HFF
    Loop
End Sub

If you want the formatting to only apply to certain cells, you can insert one of the following lines before the Dim Text As String line.

    If Target.Row <> 12 Then Exit Sub    ' Only format row "$12"
    If Target.Column <> 12 Then Exit Sub ' Only format column "$L"

Now, whenever you finish editing a cell on the worksheet, it will change the square brackets and the text inside to red. It also [works] if there are [multiple] sets of [square] brackets, but [nested [brackets] will] fail.

share|improve this answer
    
Awesome avatar icon. –  surfasb Aug 10 '11 at 1:12
    
Thanks, I had it made for my wedding. My wife's an M too. :-) –  Hand-E-Food Aug 10 '11 at 1:18
    
+2 if I could, nice going with it! I found a site that was championing a "one cell, one color" bit, and I should have known better! –  jonsca Aug 10 '11 at 1:49

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.