Excel宏将整列更改为大写

时间:2015-03-11 15:45:58

标签: excel excel-vba vba

我正在尝试更新工作簿,我必须将所有电子邮件从小写更改为大写。 我对宏还不是那么精明,但我想出了这个,但它需要永远运行。 (只有约1k行)。

Sub Uppercase()
   ' Loop to cycle through each cell in the specified range.
   For Each x In Range("B:B")
      ' Change the text in the column to uppercase letters.
      x.Value = UCase(x.Value)
   Next
End Sub

我应该使用更好的东西吗?

tl; dr我需要将整个列的大小写更改为大写。

4 个答案:

答案 0 :(得分:3)

根本不需要循环,这应该基本上立即处理:

Sub tgr()

    With Range("B1", Cells(Rows.Count, "B").End(xlUp))
        .Value = Evaluate("INDEX(UPPER(" & .Address(External:=True) & "),)")
    End With

End Sub

答案 1 :(得分:2)

立即完成整个范围:

Range("B:B") = [index(Upper(B:B),)]

答案 2 :(得分:0)

试试这个。你循环遍历B列中的每个单元格,这就是为什么它很慢。

Sub Uppercase()
   ' Loop to cycle through each cell in the specified range.
   For Each x In Range("B1:B" & Range("B" & Rows.Count).End(xlUp).Row))
      ' Change the text in the column to uppercase letters.
      x.Value = UCase(x.Value)
   Next
End Sub

答案 3 :(得分:0)

很好,但在Selection上使用这样的功能更加用户友好: (注意:任何人都可以修复此编辑!!!)

Sub ToUpper()     对于选择中的每个单元格         如果不是cell.HasFormula然后             cell.Value = UCase(cell.Value)         万一     下一个 结束子

相关问题