Consulting

Results 1 to 17 of 17

Thread: VBA - Want to load Red colored text from a cell into an array

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1

    VBA - Want to load Red colored text from a cell into an array

    I want to put all the RED colored text in a cell , into an Array. Any help will be appreciated.

    Below is situation -
    My cell contain this text -> " This is testing to Red color. "

    I want to populate an array Like , Array(0) = 'testing' and Array(1) = 'color'.

    I am able to create a function which is scanning the entire cell which gives me 'testingcolor' . I am not able to identify the spaces. i will be good if this function can give me 'testing color'.Then i can scan for spaces and create the array. T

    Function GetColorText(pRange As Range) As String
        Dim xOut As String
        Dim xValue As String
        Dim i As Long
        Dim j As Long
        xValue = pRange.Text
        j = VBA.Len(xValue)
    For i = 1 To VBA.Len(xValue)
    If pRange.Characters(i, 1).Font.Color = vbRed Then
                xOut = xOut & VBA.Mid(xValue, i, 1)
            End If
    Next
    GetColorText = xOut
    End Function
    Last edited by Aussiebear; 04-18-2019 at 12:15 AM. Reason: Wrapped submitted code in tags

Posting Permissions

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