1

通过下面的函数,我试图将公式粘贴到给定的列名中。下面的代码工作正常,但是当我的数据上升到 65K 行时,它会抛出:PasteSpecial Method range class failed 错误以及我发现在 65K 行中,当我要在代码下面运行时,物理内存使用量可能为 0是这个问题,但任何人都可以帮助我摆脱或克服这个问题。

谢谢,

尼库尼

在这里,代码详细信息:

参数:

  1. FormatRng = 包含包含公式的格式范围
  2. DataRng = 包含要粘贴复制公式的范围
  3. ColArr() = 此字符串数组包含要粘贴公式的列名

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
4

0 回答 0