简体   繁体   English

非区分大小写的格式

[英]Non Case Sensitive Formatting

I have an excel sheet that has a column that contains values such as "sick" that I want to format with strikethroughs when a button is pressed. 我有一个Excel工作表,该工作表的一列包含诸如“病态”之类的值,当按下按钮时,我想用删除线对其进行格式化。 I have the following code that works perfect if the cell value is "Sick" but not if the value is "sick" is there a way I can change the code to make it not case sensitive? 如果单元格值是“ Sick”,那么我有以下代码可以完美工作,但是如果值是“ sick”,则不是。有没有办法我可以更改代码使其不区分大小写?

For Each rng In ws.Range("E1:E" & lastrow)
If rng.Value = "Sick" Then
ws.Range("A" & rng.Row).Resize(1, 2).Font.Strikethrough = True
End If
Next rng

Change the line to: 将行更改为:

 If LCase(rng.Value) = "sick" Then

Which will look at the lower case version of the range's value and check it against the lower case string. 它将查看范围值的小写版本,并对照小写字符串进行检查。 This ensures that no matter how the range's value is capitalized, lower case will always be compared against lower case. 这样可以确保无论范围值如何大写,始终将小写与小写进行比较。

By the way, VBA also supports a UCase() function as well for converting to all upper-case, so your problem could also be solved with: 顺便说一句,VBA还支持UCase()函数以转换为所有大写字母,因此您的问题也可以通过以下方法解决:

 If UCase(rng.Value) = "SICK" Then

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM