在龙三老师提示下改的!
Sub hjs()
Dim irow%, icol%, k%
Dim rng As Range
Dim arr, arr1()
Dim aa
aa = Timer
Application.ScreenUpdating = False
Set rng = Sheet1.[a1].CurrentRegion '转换成数组之后操作,速度可以提高N倍
arr = rng '定义一个数组等于rng区域
k = 1
ReDim arr1(1 To rng.Count, 0) '重新定义一个与转换之后的单元格大小相等的数组,这个0一定要
For icol = 1 To rng.Columns.Count
For irow = 1 To rng.Rows.Count
If arr(irow, icol) <> "" Then '如果单元格不为空的时候
arr1(k, 0) = arr(irow, icol) '行列转换赋值
k = k + 1
End If
Next
Next
Sheet2.Range("a:a").ClearContents
Sheet2.Range("a1:a" & rng.Count) = arr1 '给第二个表的a列赋值
Application.ScreenUpdating = True
MsgBox "Done!共" & Format(Timer - aa, "0.0000") & "秒" '记录所用的时间
End Sub
|