Excel 2007/2010/2013 Range类的VBA运行时错误PasteSpecial方法失败

通过下面的函数,我试图将公式粘贴到给定的列名中。 下面的代码工作正常,但是当我的数据上升到65K行它的投掷:PasteSpecial方法范围类失败的错误,以及我发现在65K行当我要运行下面的代码物理内存使用将为0可能是这个问题,但任何人都帮我逃避或克服这个问题。

谢谢,

Nikunj

这里的代码细节:

参数:

  1. FormatRng =包含包含公式的格式范围
  2. DataRng =将被粘贴的复制公式的包含范围
  3. ColArr()=这个string数组包含要在其中粘贴公式的列名称

Public Function CompareFormat(FormatRng As Range, DataRng As Range, ColArr() As String) Dim ColIndexArr() As Long Dim i As Long Dim DataColRng As Range Dim FormatColRng As Rangeenter ColIndexArr = getCompColumnsPosition(DataRng, ColArr()) FormatRng.Rows(1).Copy DataRng.Rows(1).PasteSpecial xlPasteFormats, xlPasteSpecialOperationNone, False, False Application.CutCopyMode = False For i = LBound(ColIndexArr) To UBound(ColIndexArr) If ColIndexArr(i) > 0 Then Set DataColRng = Application.Intersect(DataRng.offset(1, 0), _ DataRng.Columns(ColIndexArr(i))) Set FormatColRng = Application.Intersect(FormatRng.offset(1, 0), _ FormatRng.Columns(ColIndexArr(i))) FormatColRng.Copy DataColRng.PasteSpecial xlPasteFormulas Application.CutCopyMode = False End If Next i End Function