范围内存溢出问题

问题描述 投票:0回答:1

尝试运行一个简单的宏将某些列从一个工作表复制/粘贴到另一个工作表。当我只使用几列时它工作正常,但当我添加我需要的所有列时,我会收到错误。我认为我的语法是正确的,但我听说这可能是范围/剪贴板内存问题。

Sub CopyValuesDiff()
Dim sourceWs1, dstWsDiff1, As Worksheet, dtToday As Date

dtToday = Format(DateTime.Now, "yyyy-MM-dd hh:mm:ss")
Set sourceWs1 = Sheets("Size_1")
Set dstWsDiff1 = Sheets("Diff_1")

sourceWs1.Range("H6:H300, J6:J300, L6:L300, N6:N300, AF6:AF300, AH6:AH300, AJ6:AJ300," & _
"AL6:AL300, BD6:BD300, BF6:BF300, BH6:BH300, BJ6:BJ300, CB6:CB300, CD6:CD300," & _
"CF6:CF300, CH6:CH300, CZ6:CZ300, DB6:DB300, DD6:DD300, DF6:DF300, DX6:DX300," & _
"DZ6:DZ300, EB6:EB300, ED6:ED300, EV6:EV300, EX6:EX300, EZ6:EZ300, FB6:FB300," & _
"FT6:FT300, FV6:FV300, FX6:FX300, FZ6:FZ300").Copy Destination:=dstWsDiff1.Range("B2")

dstWsDiff1.Range("A3").Value = dtToday

Application.CutCopyMode = False

End Sub
arrays excel vba range
1个回答
0
投票
    Dim arrRange, i As Long
    arrRange = Split("H6:H300,J6:J300,L6:L300,N6:N300,AF6:AF300,AH6:AH300,AJ6:AJ300," & _
        "AL6:AL300,BD6:BD300,BF6:BF300,BH6:BH300,BJ6:BJ300,CB6:CB300,CD6:CD300," & _
        "CF6:CF300,CH6:CH300,CZ6:CZ300,DB6:DB300,DD6:DD300,DF6:DF300,DX6:DX300," & _
        "DZ6:DZ300,EB6:EB300,ED6:ED300,EV6:EV300,EX6:EX300,EZ6:EZ300,FB6:FB300," & _
        "FT6:FT300,FV6:FV300,FX6:FX300,FZ6:FZ300", ",")
    For i = 0 To UBound(arrRange)
        sourceWs1.Range(arrRange(i)).Copy Destination:=dstWsDiff1.Range("B2").Offset(0, i)
    Next
© www.soinside.com 2019 - 2024. All rights reserved.