Results 1 to 10 of 12

Thread: Concatenate with style

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Fuhrer, Vierte Reich DocAElstein's Avatar
    Join Date
    Aug 2014
    Posts
    10,457
    Rep Power
    10

    Excel VBA Character.Text won’t put text in a cell of more than 255 characters. Bug or "feature”?

    Hello Abdul.
    This is an interesting problem. I am both _...
    _ not sure yet of exactly what is causing this problem: It may be a Bug or just a characteristic or a feature to which I can find no documentation.
    _ not sure yet of what would be a full solution.

    I will investigate the problem again when I have more time.

    In the meantime I have a temporary workaround that works on your test data,
    Sub ConcatWithStylesTemporarySolution()
    You may be able to adapt that to other data.
    If you have problems adapting that macro to other data, then , if you can post again some different test data, and then will try to find a solution again for you.




    Temporary Solution
    The macro below , I think , appears to give your desired output. ( In the uploaded workbook, RicksConcatWithStyles.xls , I am using a worksheet with the name of ChrTextLimit. The macro gives your full concatenated string output with styles in cell A30 in worksheet ChrTextLimit




    I will investigate this issue further when I have time. ( I have started a test post, which I will post further in later https://excelfox.com/forum/showthrea...ng-with-styles )

    Alan




    Code:
    Sub ConcatWithStylesTemporarySolution() '  https://excelfox.com/forum/showthread.php/2679-Concatenate-with-style?p=15172&viewfull=1#post15172
    Rem 0 Worksheets info
    Dim WsTest As Worksheet: Set WsTest = ThisWorkbook.Worksheets("ChrTextLimit")
    Rem 1 concatenate text strings
    '1a  make a formula  for the concatenated cells text
    Dim Cnt As Long
        For Cnt = 1 To 16 '  16 is for column P
        Dim strCelText As String
         Let strCelText = strCelText & WsTest.Cells(1, Cnt).Address & " & " & """ """ & " & "
        Next Cnt
     Let strCelText = Left(strCelText, Len(strCelText) - 8) ' take off last  " & "  and  " "  and  " & "
     Let strCelText = "=" & strCelText ' This makes the text string appear to Excel VBA as a formula
    'Debug.Print strCelText
    ' 1b  put the full concatenated text string into a cell
     WsTest.Range("A30").Clear
     Let WsTest.Range("A30").Value = strCelText
     Let WsTest.Range("A30").Value = WsTest.Range("A30").Value ' after this we now have the full text that we want, but it is all in the same  Font  styles
    Rem 2 add the styles
    Dim Position As Long: Let Position = 1 ' This varible holds the start position (within the full concatenated string) of the next text section under consideration , so at the begining it is 1
    Dim ACel As Range
        For Each ACel In Range("A1:P1") ' for each of the cells in the range of text to be concatenated with styles
            With WsTest.Range("A30").Characters(Position, Len(ACel.Value)).Font '  this is the text section within the concatenated string corrsponding to the text from the curren  ACel  cell
              .Name = ACel.Font.Name ' I am giving the text section within the long concatenated string ( LHS ) , the style from the current  ACel  cell
              .Size = ACel.Font.Size
              .Bold = ACel.Font.Bold
              .Italic = ACel.Font.Italic
              .Underline = ACel.Font.Underline
              .Color = ACel.Font.Color
              .Strikethrough = ACel.Font.Strikethrough
              .Subscript = ACel.Font.Subscript
              .Superscript = ACel.Font.Superscript
              .TintAndShade = ACel.Font.TintAndShade
              .FontStyle = ACel.Font.FontStyle
             Let Position = Position + Len(ACel.Value) + 1 ' This takes us to posiion at the end of the current cell text  +1  ( +1 is for the extra space )
            End With
        Next ACel
    End Sub
    
    Attached Files Attached Files
    Last edited by DocAElstein; 12-12-2020 at 04:43 PM. Reason: Excel VBA Character.Text won’t put text in a cell of more than 255 characters. Bug or “feature”?

  2. #2
    Junior Member
    Join Date
    Dec 2020
    Posts
    10
    Rep Power
    0
    Quote Originally Posted by DocAElstein View Post
    Hello Abdul.
    This is an interesting problem. I am both _...


    I will investigate the problem again when I have more time.
    Once Again thanks for your reply and patience. I appreciate your work. Thanks once again sir.

Similar Threads

  1. Yet Another Number-To-Words Function (Sorry, US Style Only)
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 10
    Last Post: 08-06-2020, 02:44 PM
  2. changing arrangement of data to new style
    By saied in forum Excel Help
    Replies: 3
    Last Post: 02-12-2015, 10:34 PM
  3. New Forum Style
    By Admin in forum Public News
    Replies: 2
    Last Post: 05-16-2014, 11:34 AM
  4. Replies: 6
    Last Post: 12-23-2013, 04:07 PM
  5. Excel Number Format: Indian Style Comma Separation
    By Rick Rothstein in forum Rick Rothstein's Corner
    Replies: 6
    Last Post: 09-18-2013, 11:38 AM

Posting Permissions

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