跳到主要內容

如何在Excel中將文本字符串強制轉換為大寫/小寫/適當的大小寫?

在Excel中,當您在單元格中輸入一些字母或單詞時,即使您輸入的是小寫字母或適當的大小寫字母,您仍要強製文本字符串為大寫,反之亦然。 我們大多數人可能會考慮使用Excel中的“數據驗證”功能,使用此功能,如果我們沒有輸入正確的文本大小寫,就會收到警告。 在本文中,我將介紹一些有趣的方法來根據需要強制將文本轉換為大寫,小寫或適當的大小寫。

使用數據驗證將文本字符串強制為大寫/小寫/適當大小寫

使用VBA代碼強製文本字符串為大寫/小寫/適當大小寫

使用Kutools for Excel將文本更改為大寫/小寫/大寫 好主意3


數據驗證是Excel中一個功能強大的工具,它可以幫助我們執行許多操作,借助它,我們還可以在鍵入時強制使用文本字符串的大寫,小寫或大寫形式,請執行以下操作:

1。 點擊 數據 > 數據驗證 > 數據驗證,請參見屏幕截圖:

文檔-force-大寫-1

2。 在 數據驗證 對話框,在 設定 標籤,點擊 下拉列表並選擇 習俗 選項,然後在 公式 文本框,輸入此公式 = EXACT(UPPER(A1),A1)A1 代表您將應用此功能的列,可以根據需要進行更改),請參見屏幕截圖:

文檔-force-大寫-1

3。 然後,您可以根據需要創建警報,請點擊 錯誤警報 選項卡,然後選擇 停止 來自 次數 下拉列表,位於 錯誤信息 文本框,輸入您自己的警告消息,請參見屏幕截圖:

文檔-force-大寫-1

4。 然後點擊 OK 要關閉對話框,現在當您在A列中輸入非大寫字母的文本字符串時,將彈出一個警告框,提醒您輸入大寫字母。

文檔-force-大寫-1

注意:

如果您需要強制將文本字符串轉換為小寫或適當的大小寫,請將以下公式應用於 數據驗證 在步驟2。

強制小寫:= EXACT(LOWER(A1),A1);

強制使用適當的大小寫:= EXACT(PROPER(A1),A1)


使用以下VBA代碼,當您在單元格中輸入小寫單詞時,小寫文本將自動更改為大寫字母。

1。 按住 ALT + F11 鍵,然後打開 Microsoft Visual Basic for Applications窗口.

2。 然後從左側選擇您使用的工作表 項目瀏覽器,雙擊以打開 模塊,然後將以下VBA代碼複製並粘貼到空白模塊中:

VBA代碼:強製文本字符串為大寫

Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20140603
Target.Value = VBA.UCase(Target.Value)
End Sub

文檔-force-大寫-1

3。 然後保存並關閉此代碼以返回到工作表,現在,當您輸入文本字符串時,無論其小寫還是大寫,在點擊 Enter 自動鍵。

筆記:

1.此代碼適用於整個工作表。

2.如果找不到P滾動瀏覽器窗格 在窗口中,您可以單擊 瀏覽 > 項目瀏覽器 打開它。

3.要強制使用小寫或大小寫,您可以應用以下VBA代碼:(步驟與上述相同)

VBA代碼:強製文本字符串為小寫

Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20140603
Target.Value = VBA.LCase(Target.Value)
End Sub

VBA代碼:強製文本字符串為大寫

Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20140603
Target.Value = Application.WorksheetFunction.Proper(Target.Value)
End Sub

如果您只想將某些特定的文本更改為大寫,小寫或大寫,則可以應用 變更案例 的效用 Excel的Kutools 快速完成它。

Excel的Kutools, 與以上 300 方便的功能,使您的工作更加輕鬆。 

免費安裝 Kutools for Excel,請執行以下操作:

1.選擇要更改大小寫的文本,然後單擊 庫工具 > 文本 > 變更案例。 看截圖:
文檔變更案例6

2。 在裡面 變更案例 對話框中,根據需要檢查操作選項,然後可以在 預覽 窗格。 看截圖:
文檔變更案例2

3。 點擊 Ok or 登記 和文本已更改大小寫。

 更改為大寫  更改為適當情況  更改為判刑案件
 文檔變更案例3  文檔變更案例4 文檔變更案例5 

最佳辦公生產力工具

🤖 Kutools 人工智慧助手:基於以下內容徹底改變數據分析: 智慧執行   |  生成代碼  |  建立自訂公式  |  分析數據並產生圖表  |  呼叫 Kutools 函數...
熱門特色: 尋找、突出顯示或識別重複項   |  刪除空白行   |  合併列或儲存格而不遺失數據   |   沒有公式的回合 ...
超級查詢: 多條件VLookup    多值VLookup  |   跨多個工作表的 VLookup   |   模糊查詢 ....
高級下拉列表: 快速建立下拉列表   |  依賴下拉列表   |  多選下拉列表 ....
欄目經理: 新增特定數量的列  |  移動列  |  切換隱藏列的可見性狀態  |  比較範圍和列 ...
特色功能: 網格焦點   |  設計圖   |   大方程式酒吧    工作簿和工作表管理器   |  資源庫 (自動文字)   |  日期選擇器   |  合併工作表   |  加密/解密單元格    按清單發送電子郵件   |  超級濾鏡   |   特殊過濾器 (過濾粗體/斜體/刪除線...)...
前 15 個工具集12 文本 工具 (添加文本, 刪除字符,...)   |   50+ 圖表 類型 (甘特圖,...)   |   40+ 實用 公式 (根據生日計算年齡,...)   |   19 插入 工具 (插入二維碼, 從路徑插入圖片,...)   |   12 轉化 工具 (數字到單詞, 貨幣兌換,...)   |   7 合併與拆分 工具 (高級合併行, 分裂細胞,...)   |   ... 和更多

使用 Kutools for Excel 增強您的 Excel 技能,體驗前所未有的效率。 Kutools for Excel 提供了 300 多種進階功能來提高生產力並節省時間。  點擊此處獲取您最需要的功能...

產品描述


Office選項卡為Office帶來了選項卡式界面,使您的工作更加輕鬆

  • 在Word,Excel,PowerPoint中啟用選項卡式編輯和閱讀,發布者,Access,Visio和Project。
  • 在同一窗口的新選項卡中而不是在新窗口中打開並創建多個文檔。
  • 將您的工作效率提高 50%,每天為您減少數百次鼠標點擊!
Comments (10)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Please suggest modifications in the VBA code to force the text strings to change to the desired format (Upper/Lower/Proper case) in selected/specified cells only rather than changing the Case of the text strings in the entire worksheet.
This comment was minimized by the moderator on the site
Hello, DS,
To apply the code to a specified range instead of entire worksheet, please apply the following code:
VBA code: Force text string to uppercase
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim SpecifiedRange As Range
    Set SpecifiedRange = Me.Range("A1:A10")
    If Not Intersect(Target, SpecifiedRange) Is Nothing Then
        Application.EnableEvents = False
        Target.Value = VBA.UCase(Target.Value)
        Application.EnableEvents = True
    End If
End Sub


VBA code: Force text string to lowercase
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim SpecifiedRange As Range
    Set SpecifiedRange = Me.Range("A1:A10")
    If Not Intersect(Target, SpecifiedRange) Is Nothing Then
        Application.EnableEvents = False
        Target.Value = VBA.LCase(Target.Value)
        Application.EnableEvents = True
    End If
End Sub


VBA code: Force text string to propercase
Private Sub Worksheet_Change(ByVal Target As Range)
    Dim SpecifiedRange As Range
    Set SpecifiedRange = Me.Range("A1:A10")
    If Not Intersect(Target, SpecifiedRange) Is Nothing Then
        Application.EnableEvents = False
        Target.Value = Application.Proper(Target.Value)
        Application.EnableEvents = True
    End If
End Sub


Please have a try, thank you!
This comment was minimized by the moderator on the site
Use: On Error Resume Next

Private Sub Worksheet_Change(ByVal Target As Range)
'Update 20140603
On Error Resume Next
Target.Value = Application.WorksheetFunction.Proper(Target.Value)
End Sub
This comment was minimized by the moderator on the site
muchas gracias, sirvio enormemente estos codigos
This comment was minimized by the moderator on the site
This worked for me, however if you went to delete the contents of the cell then a "runtime error '13': type mismatch" came up

Any ideas?
This comment was minimized by the moderator on the site
i have the same problem. if you know how to deal with it please tell me!
This comment was minimized by the moderator on the site
Hello, which method you use will come up the errors?
This comment was minimized by the moderator on the site
Like your VBA solution, but how could I limit it to a single column and format other columns differently, e.g., columns A and C force uppercase, column B force proper case?
This comment was minimized by the moderator on the site
I do not know which VBA can handle your job (some columns in uppercase, some in proper case), but the data validation can solve it, why do not use it?
This comment was minimized by the moderator on the site
thanks for the macro to convert all entries to capital letters, but is there something i need to do to stop the macro from crashing excel every fe minutes? Appreciate the help!
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations