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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 20:54:00  来源:igfitidea点击:

Excel VBA code to upper case all cells

excel-vbasharepoint-2010excel-2010vbaexcel

提问by What'sUP

Goal:
The goal is to gain the result from the picture below

目标:
目标是从下图得到结果

enter image description here

在此处输入图片说明

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 代码获得目标结果。

enter image description here

在此处输入图片说明

回答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

enter image description here

在此处输入图片说明

回答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