如果在一列中存入不规则的海量数据,数字和字符串混合,现在需要提取数字,总共总结出下面四中方法,依据运行速度快慢依次排列,推荐使用前三种方法:
第一种:数组方法,速度最快
y3231057_1() t = Timer Arr, i&, j%, k&, S$, SS$, $ Arr1() Arr = Range( & [a65536].End(xlUp).Row) k = (Arr) Arr1( k, ) i = k S = Arr(i, ) j = (S) SS = (S, j, ) SS Like = & SS j Arr1(i, ) = = i [B1].Resize(k, ) = Arr1 [d65536].End(xlUp).Offset(, ) = Timer - t
第二种:正则表达式的方法,速度较数组方法稍慢
y3231057_2() t = Timer Arr, i& Arr1() Arr = Range( & [a65536].End(xlUp).Row) k = (Arr) Arr1( k, ) () i = k .Pattern = .Global = Arr1(i, ) = .Replace(Arr(i, ), ) i [B1].Resize(k, ) = Arr1 [f65536].End(xlUp).Offset(, ) = Timer - t
第三种:遍历需转换字符,依据需转换字符批量转换方法,速度叫正则表达式方法稍慢
y3231057_3() t = Timer Arr k rng Range Application.ScreenUpdating = Arr = Array(, , , , , , ) rng = Range( & Sheet1.[C65536].End(xlUp).Row) k = (Arr) rng.Replace what:=Arr(k), replacement:= rng = Application.ScreenUpdating = [g65536].End(xlUp).Offset(, ) = Timer - t
第四种:依据单元格循环,一个一个转换方法,速度很慢,约为上面几种方法用时的几百倍
y3231057_4() t = Timer Arr i k Arr = Array(, , , , , , ) i = [a65536].End(xlUp).Row k = (Arr) Cells(i, ).Replace Arr(k), [e65536].End(xlUp).Offset(, ) = Timer - t
时间: 2024-10-23 22:24:24