0

这是一个微不足道的错误,但我无法弄清楚。我有一个复制和粘贴几个项目的 vba 脚本。它适用于除最后一个之外的所有内容。错误是

无法粘贴信息,因为复制区域和粘贴区域的大小和形状不同。尝试以下方法之一:

  1. 单击单个单元格,然后粘贴。•</li>
  2. 选择一个大小和形状相同的矩形,然后粘贴。

这是代码:

Sub MakePropertyPage(propertyNum, aFile)
Dim sheetName As String
sheetName = "Prop " & propertyNum

'OPENS INDIVIDUAL WORKBOOKS TO PULL IN INPUT INFORMATION
Workbooks.Open Filename:=vpath & ThisWorkbook.Path & "\" & aFile & ".xlsb",                 UpdateLinks:=False, ReadOnly:=True

Dim sourceRangeAsString As String, dest As Range, clearArea As Range
Dim sheetToEdit As Worksheet
Set sheetToEdit = ThisWorkbook.Sheets(sheetName)

Set clearArea = sheetToEdit.Range("AL100:CC900")
clearArea.Delete

sourceRangeAsString = "RentRoll"
Set dest = sheetToEdit.Range("AL100")
Call CopyAndPaste(Workbooks(aFile & ".xlsb"), sourceRangeAsString, dest)

sourceRangeAsString = "Underwriting"
Set dest = sheetToEdit.Range("AL300")
Call CopyAndPaste(Workbooks(aFile & ".xlsb"), sourceRangeAsString, dest)

sourceRangeAsString = "Projections"
Set dest = sheetToEdit.Range("AL400")
Call CopyAndPaste(Workbooks(aFile & ".xlsb"), sourceRangeAsString, dest)

sourceRangeAsString = "RolloverCalculations"
dest = sheetToEdit.Range("AL500")
Call CopyAndPaste(Workbooks(aFile & ".xlsb"), sourceRangeAsString, dest)



'Close the workbook now that we are done with it
Workbooks(aFile & ".xlsb").Close savechanges:=False
End Sub

Sub CopyAndPaste(sourceFile, sourceRangeAsString, dest)
    Set source = sourceFile.Names(sourceRangeAsString).RefersToRange
    source.Copy
    dest.PasteSpecial (xlPasteValues)
    source.Copy
    dest.PasteSpecial (xlPasteFormats)
End Sub
4

1 回答 1

3

你在Set这里缺少一个:

dest = sheetToEdit.Range("AL500")
于 2012-06-16T00:03:26.487 回答