簡體   English   中英

Excel 條件正確大小寫格式

[英]Excel Conditional Proper Case Formatting

我正在嘗試將單元格中的文本轉換為正確大小寫格式,但某些縮寫詞(比如“DAD”、“ABC”、“CBD”)除外,它們應該是大寫字母。

Proper Case Conversion and Conditional Formatting的這些鏈接中,我需要使用Select Case語句,但我不知道如何實現它。

Sub ProperCase()
Dim Rng As Range
Dim WorkRng As Range

On Error Resume Next
xTitleID = "Conditional Proper Case Conversion"

Set WorkRng = Application.Selection
Set WorkRng = Application.InputBox("Range", xTitleID, WorkRng.Address, Type:=8)

For Each Rng In WorkRng
    Rng.Value = Application.WorksheetFunction.Proper(Rng.Value)
Next
End Sub

此代碼請求一系列單元格來執行轉換。

如何為某些字符串/文本(即縮寫)添加條件功能?

這應該這樣做:

Sub ProperCase()
    Dim r As Range
    Const EXCEPTIONS$ = ".dad.abc.cbd."
    
    On Error Resume Next
    For Each r In Application.InputBox("Range", "Conditional Proper Case Conversion", Selection.Address, Type:=8)
        If InStrB(EXCEPTIONS, "." & LCase(r) & ".") Then
            r = UCase(r)
        Else
            r = WorksheetFunction.Proper(r)
        End If
    Next
End Sub

只需編輯 EXCEPTIONS 常量。 確保句點跨越 EXCEPTIONS 字符串中的每個項目。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM