[英]ActiveSheet.Range().PasteSpecial not working
I'm trying to paste values using the activesheet.我正在尝试使用 activesheet 粘贴值。 The code keeps throwing out the following error:代码不断抛出以下错误:
"To do this, all the merged cells need to be the same size" “要做到这一点,所有合并的单元格都需要具有相同的大小”
But none of the cells I'm copying are merged.但是我正在复制的单元格都没有合并。 The error comes from the line: ActiveSheet.Range("C23").PasteSpecial...
错误来自以下行: ActiveSheet.Range("C23").PasteSpecial...
Dim FM As Worksheet: Set FM = ThisWorkbook.Sheets("Closings Template")
fmPath = "G:\Finance Department\Banking Dashboard\"
FmFile = "Testing_Testing.xlsm"
fmRef = fmPath & FmFile
ToPath = "G:\Budgets and Financial\CLT Budget Templates\"
ToFile = "Belle Grove Manor.xlsx"
ToRef = ToPath & ToFile
CIWPath = "H:\02-CHARLOTTE\Land\zLand Worksheets\"
CIWFile = "Community Information Workbook_CLT.xlsm"
CIWRef = CIWPath & CIWFile
FM.Range("O2").Copy
Workbooks.Open(ToRef).Worksheets("Sheet1").Activate
ActiveSheet.Range("C11").PasteSpecial Paste:=xlPasteValues
FM.Range("P2").Copy
ActiveSheet.Range("C17").PasteSpecial Paste:=xlPasteValues
ActiveSheet.Range("C15").Value = "14"
Application.CutCopyMode = False
Workbooks.Open(CIWRef).Worksheets("BLSRG.PS").Range("N23").Copy
ActiveSheet.Range("C23").PasteSpecial Paste:=xlPasteValues
ActiveSheet.Range("C19").Copy
FM.Range("N2").PasteSpecial Paste:=xlPasteValues
Application.CutCopyMode = False
Using ActiveSheet
can cause problems and setting up your variable properly will ensure errors are eliminated.使用ActiveSheet
可能会导致问题,正确设置变量将确保消除错误。 Try to incorporate the simple code below.尝试合并下面的简单代码。
Dim wbSrc As Workbook
Set wbSrc = Workbooks.Open(CIWRef) 'the source workbook
Dim wsSrc As Worksheet
wsSrc = wbSrc.Sheets("BLSRG.PS") 'the source worksheet
Dim wbDest As Workbook
Set wbDest = Workbooks.Open(ToRef) 'the destination workbook
Dim wsDest As Worksheet
wsDest = wbDest.Sheets("Sheet1") 'the destination worksheet
wsDest.Range("C23").Value = wsSrc.Range("N23").Value 'writes the values from the source worksheet to the destination worksheet
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.