Free Excel macros

Add UPPER

Capitalises the text in your selection, whether it's typed text or the result of a formula.

This macro uses Turn Stuff Off/On, so add those two to the same module first.

VBA: Add UPPER Function

Sub Add_UPPER() 'This macro is used to capitalise cell values; obtained from bgrconsulting.co.uk/macros where help and support can be found.

On Error Resume Next
If Selection.Cells.Count = 1 Then
    Set oRng = Selection
Else
    Set oRng = Selection.SpecialCells(xlCellTypeVisible)
    Set oRngC = oRng.SpecialCells(xlCellTypeConstants)
    Set oRngF = oRng.SpecialCells(xlCellTypeFormulas)
    If oRngC Is Nothing Or oRngF Is Nothing Then
        If oRngC Is Nothing Then Set oRng = oRngF
        If oRngF Is Nothing Then Set oRng = oRngC
    Else
        Set oRng = Union(oRngC, oRngF)
    End If
End If

For Each Cell In oRng
    If Not IsNumeric(Cell.Value) Then
        If nRng Is Nothing Then Set nRng = Cell Else Set nRng = Union(nRng, Cell)
    End If
Next Cell
If nRng Is Nothing Then MsgBox "No cells in your selection contain numeric values; nothing happened.", vbOKOnly, "Try again:": Exit Sub

If MidSub <> vbYes Then Call TurnStuffOff
For Each Cell In nRng
    If InStr(Cell.Formula, "UPPER(") Then GoTo NextCell
    If Left(Cell.Formula, 1) = "=" Then Cell.Formula = "=UPPER(" & Mid(Cell.Formula, 2, 9999) & ")" Else Cell.Formula = UCase(Cell.Formula)
NextCell:
Next Cell
If MidSub <> vbYes Then Call TurnStuffOn: MsgBox "All visible text strings within the selection have been capitalised.", vbOKOnly, "Success!"
End Sub

New to macros? Set up your Personal Macro Workbook first, then paste this code into its module.