Create Custom Functions in Excel 2007, 2010, 2013

1. Press Alt+F11 to open the Visual Basic Editor, and then click Insert, Module.




2. Write your function here
Such as here is the function to get Red text in a Cell. It's very useful :)

Function GetRedText(pRange As Range) As String
   
    Dim xOut As String
    Dim xValue As String
    Dim i As Long
    xValue = pRange.Text

    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

    GetRedText = xOut
End Function

No comments:

Post a Comment