+ Reply to Thread
Results 1 to 12 of 12

Rich Text Formatting After Carriage Return

Hybrid View

  1. #1
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Rich Text Formatting After Carriage Return

    Hello coding experts,

    Hopefully a relatively straightforward problem. I have a list of products and descriptions setup in an excel table. I reference the product elsewhere in the workbook, and pull the description beneath it using two carriage returns, as such:

    =C4&""&INDEX(MY_TABLE_DESCRIPTION,MATCH(C4,MY_TABLE_PRODUCT,0))

    Can someone point me in the right direction for creating a loop that will format the description (text found after the carriage returns) as size 8 font? Please note that this will (hopefully) be applied to other multiple sheets.
    Last edited by Leith Ross; 06-03-2015 at 02:05 PM.
    Spread the love, add to the Rep

    "None of us are as smart as all of us."

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Rich Text Formatting After Carriage Return

    Hello mcmahobt,

    This will require a VBA macro as this can not be done using formulas. Since you are using formulas, it will be necessary to see your workbook to prevent the VBA macro from altering the formulas.
    Sincerely,
    Leith Ross

    Remember To Do the Following....

    1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.
    2. Thank those who have helped you by clicking the Star below the post.
    3. Please mark your post [SOLVED] if it has been answered satisfactorily.


    Old Scottish Proverb...
    Luathaid gu deanamh maille! (Rushing causes delays!)

  3. #3
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Rich Text Formatting After Carriage Return

    Thanks for the info Leith. I was aware this would require VBA, so hopefully someone such as yourself who is more skilled than I can power through this. See attached for a sample workbook. The goal is to have the description that is being pulled in the formula within cells in column B by the INDEX/MATCH formula after the carriage returns to be formatted as text that is size 8.
    Attached Files Attached Files

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Rich Text Formatting After Carriage Return

    Hello mcmahobt,

    Thanks for posting the workbook. Which worksheet should I be looking at?

  5. #5
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Rich Text Formatting After Carriage Return

    Sorry for the confusion, I wanted to mimic my data as closely as possible to make things easier in the long run when implementing a solution. The sheet that I am hoping to run the VBA code on is Sheet2.

  6. #6
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Rich Text Formatting After Carriage Return

    Hello mcmahobt,

    In your first post you said:
    Can someone point me in the right direction for creating a loop that will format the description (text found after the carriage returns) as size 8 font?
    I am still not sure where you are referring to on Sheet2?

  7. #7
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Rich Text Formatting After Carriage Return

    On Sheet2, there are merged cells in column B. Merged cell B4:23, for example, contains the formula:

    =C4&"
    
    "&INDEX(Table1[Description],MATCH(C4,Table1[Product],0))
    This pulls the product name from column C, as well as the corresponding description of that product from Sheet1. What I'm hoping to achieve is a macro that will loop through the merged cells in column B, and format the INDEX/MATCH portion of the formulas found in each merged cell in column B, and format them to be size 8 text.

  8. #8
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Rich Text Formatting After Carriage Return

    Hello mcmahobt,

    Thanks, now it makes sense. That piece about column "B" is what was missing.

  9. #9
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Rich Text Formatting After Carriage Return

    No worries, things often get lost over the airwaves. Please let me know if you have any more questions if you get a chance to look at the problem.

  10. #10
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Rich Text Formatting After Carriage Return

    Hello mcmahobt,

    Houston, we have a problem. It appears that the font size of a merged cell whose output is from a formula can only be one size. While my macro runs without error, the font size of the cells remains unchanged.

    Sub ResizeDescriptions()
    
        Dim Cell As Range
        Dim i As Long
        Dim n As Long
        Dim row As Long
        Dim Rng As Range
        Dim RngBeg As Range
        Dim RngEnd As Range
        Dim Wks As Worksheet
        
            Set Wks = Worksheets("Sheet2")
            
            Set RngBeg = Wks.Range("B4")
            Set RngEnd = Wks.Cells(Rows.Count, RngBeg.Column).End(xlUp)
            Set Rng = Wks.Range(RngBeg, RngEnd)
            
            If RngEnd.row < RngBeg.row Then Set Rng = RngBeg
            
                For row = 1 To Rng.Rows.Count
                    Set Cell = Rng.Cells(row, 1)
                    If Cell.MergeCells = True Then
                          ' Code to change description font size to 8.
                            i = InStr(1, Cell, vbLf & vbLf) + 2
                            n = Len(Cell)
                            Cell.Characters(i, n - i + 1).Font.Size = 8
                        row = row + Cell.MergeArea.Rows.Count - 1
                    End If
                Next row
                
    End Sub
    Attached Files Attached Files
    Last edited by Leith Ross; 06-03-2015 at 04:42 PM.

  11. #11
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,259

    Re: Rich Text Formatting After Carriage Return

    Just to clarify your formula for others, it can be written this way...
    =C4&REPT(CHAR(10),2)&INDEX(Table1[Description],MATCH(C4,Table1[Product],0))

  12. #12
    Forum Expert
    Join Date
    09-11-2014
    Location
    Washington, DC
    MS-Off Ver
    2016
    Posts
    1,907

    Re: Rich Text Formatting After Carriage Return

    Do'h!

    Well, back to the drawing board then. I suppose I can split the merged cell and manually adjust the font size, then drag down the formulas manually. Relatively pain free. I appreciate the help regardless, thanks for taking a look!

+ 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. Replace text string in a cell and retain rich text formatting (Excel 2013)
    By CharlieBear in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 04-15-2015, 04:39 PM
  2. [SOLVED] Add Carriage Return to a text string?
    By NewYears1978 in forum Excel General
    Replies: 2
    Last Post: 03-29-2014, 01:06 AM
  3. carriage return without wrap text?
    By Paul Stockdale in forum Excel General
    Replies: 2
    Last Post: 06-12-2013, 06:28 AM
  4. carriage return in a text cell
    By dockdude in forum Excel General
    Replies: 1
    Last Post: 02-25-2011, 04:12 PM
  5. Carriage Return in General Text Box?
    By Al Franz in forum Excel General
    Replies: 1
    Last Post: 01-24-2005, 05:06 PM

Tags for this Thread

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