Convert entire range to lowercase without looping through cells Indirect

天涯浪子 提交于 2019-12-01 16:07:08

Try this:

Range("A1:A" & n) = Application.Evaluate("index(lower(A1:A" & n & "),)")

Looping through the worksheet's cell will slow this down. Grab all of the cell data, process it in memory and then dump the result back to the worksheet.

Sub makeLower()
    Dim v As Long, vLWRs As Variant

    With Worksheets("Sheet1")
        With .Range(.Cells(1, 1), .Cells(Rows.Count, 1).End(xlUp))
            vLWRs = .Value2
            For v = LBound(vLWRs, 1) To UBound(vLWRs, 1)
                vLWRs(v, 1) = LCase(vLWRs(v, 1))
            Next v
            .Cells = vLWRs
        End With
    End With
End Sub

Tested on 50K cell in 0.3 seconds, 1M cells in 6.78 seconds.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!