Excel VBA 代码将所有单元格大写
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16289540/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Excel VBA code to upper case all cells
提问by What'sUP
Goal:
The goal is to gain the result from the picture below
目标:
目标是从下图得到结果
Problem:
The current situation is below
问题:
目前情况如下
How should I do it in order to gain the result in the goal by using VBA code.
我应该如何做才能通过使用 VBA 代码获得目标结果。
回答by mattboy
Dim rng As Range
Dim cell As Range
Set rng = Range("C4:F7")
For Each cell In rng
cell.Value = UCase(cell)
Next cell
回答by Santosh
Try this code
试试这个代码
Sub sample()
Range("B4:E7") = [index(upper(B4:E7),)]
End Sub
回答by Charles Clayton
The previous answers make you include a range. This works if you're talking about all cells.
以前的答案使您包含一个范围。如果您谈论的是所有单元格,这将起作用。
sub EverythingToUpperCase()
For Each Cell in ActiveSheet.UsedRange.Cells
Cell.Value = UCase(Cell.value)
Next
End Sub
回答by davexx
shortest versions i have seen:
我见过的最短版本:
With Target '(end with at bottom)
With Target '(以底部结尾)
Target = UCase(Target) 'Ucase or Lcase
'Target = StrConv(Target, vbProperCase) '<< PROPER
AND.. Thee 1 Liner ?:
和.. 你 1 班轮?:
Selection.Value = UCase(Selection.Value) 'YES << 1 LINER UCASE (tested, worked), add a range