[英]Excel Conditional Proper Case Formatting
I am trying to convert text in cells to Proper Case format, except certain abbreviations (lets say "DAD", "ABC", "CBD"), which should be Upper Case.我正在尝试将单元格中的文本转换为正确大小写格式,但某些缩写词(比如“DAD”、“ABC”、“CBD”)除外,它们应该是大写字母。
From these links for Proper Case Conversion and Conditional Formatting , I need to use the Select Case
statement, but I am not sure how to implement it.从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
This code requests a range of cells to perform the conversion on.此代码请求一系列单元格来执行转换。
How do I add the conditional functionality for certain strings/text (ie abbreviations)?如何为某些字符串/文本(即缩写)添加条件功能?
This should do it:这应该这样做:
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
Just edit the EXCEPTIONS constant.只需编辑 EXCEPTIONS 常量。 Make sure that a period straddles every item in the EXCEPTIONS string.
确保句点跨越 EXCEPTIONS 字符串中的每个项目。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.