Excel - Visual Basic

How to Create Custom Excel Functions

Create custom functions in Excel

EXCEL REGEX TUTORIAL (REGULAR EXPRESSIONS)

Functions

Find set of numbers in string

Public Function NAJDI_PSC(str As String) As String

    Set regex = CreateObject("VBScript.RegExp")
    
    With regex
      .Pattern = "[0-9]{3}[\s]*?[0-9]{2}"
      .Global = True
    End With
    
    Set objMatches = regex.Execute(str)
    
    If objMatches.Count > 0 Then
         For Each objMatch In objMatches
              Psc = CStr(objMatch.Value)
              Psc = Replace(Psc, " ", "")
              NAJDI_PSC = Psc
              Exit Function
         Next
    End If
    
    NAJDI_PSC = ""
    Exit Function
    
End Function

Extract cell text characteristics

Public Function myColor(r As Range) As Integer
    myColor = r.Font.ColorIndex
End Function

Private Function bold(r As Range) As Integer
    bold = r.Font.bold
End Function

Public Function BoldText(r As Range) As String
    If r.Font.Bold = True Then
        BoldText = "A"
    Else
        BoldText = "N"
    End If
End Function