跳到主要内容

如何在Excel中将文本字符串强制转换为大写/小写/适当的大小写?

在Excel中,当您在单元格中输入一些字母或单词时,即使您输入的是小写字母或适当的大小写字母,您仍要强制文本字符串为大写,反之亦然。 我们大多数人可能会考虑使用Excel中的“数据验证”功能,如果使用此功能,当我们键入的文本不正确时,会收到警告。 在本文中,我将介绍一些有趣的方法来根据需要强制将文本转换为大写,小写或适当的大小写。

使用数据验证将文本字符串强制为大写/小写/适当大小写

使用VBA代码强制文本字符串为大写/小写/适当大小写

使用 Kutools for Excel 将文本更改为大写/小写/正确大小写 好主意3


数据验证是Excel中一个功能强大的工具,它可以帮助我们执行许多操作,借助它,我们还可以在键入时强制使用文本字符串的大写,小写或大写形式,请执行以下操作:

1。 点击 时间 > 数据验证 > 数据验证,请参见屏幕截图:

文档-force-大写-1

2。 在 数据验证 对话框,在 个人设置 标签,点击 下拉列表并选择 定制版 选项,然后在 公式 文本框,输入此公式 = EXACT(UPPER(A1),A1)A1 代表您将应用此功能的列,可以根据需要进行更改),请参见屏幕截图:

文档-force-大写-1

3。 然后,您可以根据需要创建警报,请点击 错误警报 选项卡,然后选择 Stop 停止 来自 样式 下拉列表,位于 错误信息 文本框,输入您自己的警告消息,请参见屏幕截图:

文档-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。 然后保存并关闭此代码以返回到工作表,现在,当您输入文本字符串时,无论其小写还是大写字母,在点击 输入 自动键。

笔记:

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

如果您只想将某些特定的文本更改为大写,小写或大写,则可以应用 变更案 实用程序 Kutools for Excel 快速完成它。

Kutools for Excel, 与超过 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 Tab 为 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