excel sheet中数据的快速复制

'利用Copymemory 复制数组,实现excel sheet中数据的任意复制,粘贴区域小于复制区域,数据将被截取,否则将用空格填充


Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (pDst As Any, pSrc As Any, ByVal ByteLen As Long)

Sub copyrange(ByVal src As Range, ByVal dest As Range) ' copy all data from src to dest
Dim arrsrc(), arrdest()
arrsrc = src
arrdest = dest
ReDim arrdest(1 To dest.Rows.Count, 1 To dest.Columns.Count)
CopyMemory ByVal VarPtr(arrdest(1, 1)), ByVal VarPtr(arrsrc(1, 1)), 16 * src.Rows.Count * src.Columns.Count
dest = arrdest
Erase arrsrc
Erase arrdest
End Sub

Sub xxx() '将a1:c100 区域数据复制到d3:h40
copyrange Range("a1:c100"), Range("d3:h40")
End Sub

你可能感兴趣的:(Excel)