Excel 有条件的正确大小写格式
Excel Conditional Proper Case Formatting
我正在尝试将单元格中的文本转换为正确的大小写格式,但某些缩写(比方说“DAD”、“ABC”、“CBD”)除外,它们应该是大写。
从 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
此代码请求一系列单元格以执行转换。
如何为某些 strings/text(即缩写)添加条件功能?
应该这样做:
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 字符串中的每一项。
我正在尝试将单元格中的文本转换为正确的大小写格式,但某些缩写(比方说“DAD”、“ABC”、“CBD”)除外,它们应该是大写。
从 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
此代码请求一系列单元格以执行转换。
如何为某些 strings/text(即缩写)添加条件功能?
应该这样做:
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 字符串中的每一项。