+ Reply to Thread
Results 1 to 8 of 8

Format text between brackets with text before and after

  1. #1
    Registered User
    Join Date
    05-27-2015
    Location
    Florida, US
    MS-Off Ver
    2013
    Posts
    33

    Format text between brackets with text before and after

    Hello,

    I've been searching the forum and other websites looking for something that would solve my problem hopefully this will be my last stop =].

    I have to type reports and some of the features are formatted into cybermetricsGDT font which requires you to use special characters within brackets. The problem is i have to manually click on each cell, highlight, and then change the font type and size when it has leading text or text following the bracketed information.

    I would like to be able to make the report with the above text and then run the code to change the font to cybermetricsGDT and the font size to 12.

    examples of the text to be converted: "2x [.@**]" or "3x [Š[.)!)[A[B[C] EQUALLY SPACED" but sometimes its just "[.@**]"

    Thank you sooo much in advance

    -Javier

    Edit: If it helps the information is always in the D column starting at row 45 and can go down to row 68
    Last edited by jafvortex93; 05-27-2015 at 10:21 AM.

  2. #2
    Registered User
    Join Date
    05-27-2015
    Location
    Florida, US
    MS-Off Ver
    2013
    Posts
    33

    Re: Format text between brackets with text before and after

    I can scrub the original file and upload it in case it might help a bit.

  3. #3
    Registered User
    Join Date
    03-26-2014
    Location
    Nowhere, somewhere
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Format text between brackets with text before and after

    Something like this should do it.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    05-27-2015
    Location
    Florida, US
    MS-Off Ver
    2013
    Posts
    33

    Re: Format text between brackets with text before and after

    a couple questions, with this i would need to put it every possible entry it could be right? There is an infinite amount of possibilities, that's why i was looking at something where it was just looking at any information between the brackets. I added a test file that shows part of a report with just some of the possibilities. Thank you!
    Attached Files Attached Files

  5. #5
    Registered User
    Join Date
    03-26-2014
    Location
    Nowhere, somewhere
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Format text between brackets with text before and after

    Ok, I misunderstood your need.

    I can understand where to start and end with these two examples: "2x [.@**]", "[.@**]"
    But how would you mark this one: "3x [S[.)!)[A[B[C] EQUALLY SPACED" ?

    "3x [S[.)!)[A[B[C] EQUALLY SPACED" or "3x [S[.)!)[A[B[C] EQUALLY SPACED"

    Is the pattern strictly open bracket, some characters, close bracket? Can there be more than one such pattern in a string?

  6. #6
    Registered User
    Join Date
    05-27-2015
    Location
    Florida, US
    MS-Off Ver
    2013
    Posts
    33
    It would never be more than one of those in a cell block. And it would always be open bracket till the end of the feature where it closes it out. Would searching for open bracket, counting the number of characters between it and a closed bracket, and then applying the font settings from bracket open to bracket close work better/easier?


    Quote Originally Posted by TnTinMN View Post
    Ok, I misunderstood your need.

    I can understand where to start and end with these two examples: "2x [.@**]", "[.@**]"
    But how would you mark this one: "3x [S[.)!)[A[B[C] EQUALLY SPACED" ?

    "3x [S[.)!)[A[B[C] EQUALLY SPACED" or "3x [S[.)!)[A[B[C] EQUALLY SPACED"

    Is the pattern strictly open bracket, some characters, close bracket? Can there be more than one such pattern in a string?

  7. #7
    Registered User
    Join Date
    03-26-2014
    Location
    Nowhere, somewhere
    MS-Off Ver
    Excel 2007
    Posts
    75

    Re: Format text between brackets with text before and after

    Quote Originally Posted by jafvortex93 View Post
    It would never be more than one of those in a cell block. And it would always be open bracket till the end of the feature where it closes it out. Would searching for open bracket, counting the number of characters between it and a closed bracket, and then applying the font settings from bracket open to bracket close work better/easier?
    It is definitely easier.

    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    05-27-2015
    Location
    Florida, US
    MS-Off Ver
    2013
    Posts
    33

    Re: Format text between brackets with text before and after

    That was amazing!!!! Thank you VERY much! The only thing i changed was that i added the font size (not sure if i did in the most practical/savvy way but...eh), just wanted to throw it on here for future visitors. Again, thank you.

    Sub ChangeFont()
    Const fontName As String = "CybermetricsGDT"

    Dim ws As Excel.Worksheet
    Set ws = ActiveSheet ' *** change this to your worksheet

    Dim colRange As Excel.Range
    Set colRange = Application.Intersect(ws.Columns("D"), ws.UsedRange)

    Dim cell As Excel.Range
    Dim tmp As String
    Dim posOpenBracket As Integer, posCloseBracket As Integer
    For Each cell In colRange
    tmp = cell.Value
    posOpenBracket = InStr(1, tmp, "[", vbTextCompare)
    If posOpenBracket > 0 Then
    posCloseBracket = InStrRev(tmp, "]", , vbTextCompare)
    If posCloseBracket > 0 And posCloseBracket > posOpenBracket Then
    cell.Characters(posOpenBracket, (posCloseBracket - posOpenBracket) + 1).Font.Name = fontName
    cell.Characters(posOpenBracket, (posCloseBracket - posOpenBracket) + 1).Font.Size = 12
    End If
    End If
    Next cell
    End Sub

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Remove text between [brackets]
    By Benni5555 in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 07-26-2014, 01:17 AM
  2. formatting brackets for text
    By Michaelxxx in forum Excel General
    Replies: 1
    Last Post: 08-26-2011, 03:58 PM
  3. Text Within Parenthesis (brackets)
    By vsssarma in forum Excel General
    Replies: 3
    Last Post: 11-12-2010, 08:02 PM
  4. Extracting Text from a string of text between brackets
    By easty in forum Excel - New Users/Basics
    Replies: 11
    Last Post: 12-02-2009, 11:29 AM
  5. Custom format a text cell with square brackets: [ ] ?
    By StargateFan in forum Excel General
    Replies: 2
    Last Post: 02-06-2005, 12:06 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1