Excel VBA: Turn all letters into "upper case"

When processing data in Excel (especial inputing values & outputting as reports), we might require (sometimes just prefer) some cells with all upper case letters (ex: ABC instead of Abc). In Word, we have a function to do so in the toolbar. In Excel, can you expect us to replace one letter by another?

I have written an Excel Macro (VBA Sub), and setup with a hot key. It will make all the selected cells into upper case letters.
You may apply to lower case letters by using LCase instead of UCase in the Macro.

【中文版】
當在Excel裡面處理資料的時候,偶會有需要(或期望)資料格內的自母權都是大寫(尤其是輸入資料或要把資料作成報告),舉例來說,想要把Abc改成ABC。在Word內有內建的功能可以執行大小寫轉換,但總不能要我們在Excel把字母一個一個用取代的方式轉換吧?
我寫了一個Excel巨集(VBA函式)並設定快速鍵,它可把選取的儲存格內資料全轉成大寫。相同的道理,只要把使用的UCase改成LCase就可改成全都小寫了。

Sub Format_2_Upper()
    Dim selRange As Range, intAC As Integer, intIC As Integer, i As Integer, j As Integer
    If (TypeName(Selection) = "Range") Then
        Set selRange = Selection
        intAC = selRange.Areas.Count
        For i = 1 To intAC
            intIC = selRange.Areas(i).Count
            For j = 1 To intIC
                selRange.Areas(i).Item(j).Value = UCase(selRange.Areas(i).Item(j).Value)
            Next j
        Next i
    End If
End Sub

留言

這個網誌中的熱門文章

Excel技巧(1):檔案肥大的原因,附上減肥撇步

Excel技巧(2):拜託殺了那些看不見的空白吧!

Excel版本與檔案格式