宏打开 - 复制 - 从外部文件关闭回主文件。从一个特定文件复制产生问题。
附加是代码和**以指示错误发生的位置。
Sub UpdateDate_Click()
Dim readLastCell As Long
Dim readLastCellNameSheet As Long
Dim billNumber
Dim SheetName As String
Dim billNumberNamesheet As Long
Dim ExecutiveWorkBookPath As String
Dim excelFilePath
Dim ExecutiveWorkBook As Workbook
Dim MainTemplate As String
MainTemplate = ThisWorkbook.Name
'ChDir Defaulth path
excelFilePath = Application.ActiveWorkbook.Path + "\"
Application.EnableEvents = False
strFilename = Dir(excelFilePath & "\*xlsm")
Do While strFilename <> ""
'Set variable equal to opened workbook
If InStr(strFilename, "Executive") > 0 Then
Set ExecutiveWorkBook = Workbooks.Open(excelFilePath & strFilename, ReadOnly:=True)
ExecutiveWorkBook.Worksheets("Summary").Unprotect "12345+"
ExecutiveWorkBook.Worksheets("Summary").Range("A1:Q220000").Locked = False
readLastCell = ThisWorkbook.Sheets("Master").Cells(Rows.Count, 1).End(xlUp).Row
readLastCellNameSheet = ExecutiveWorkBook.Sheets("Summary").Cells(Rows.Count, 1).End(xlUp).Row
For x = 4 To readLastCell
cell = "A" & x
billNumber = ThisWorkbook.Worksheets("Master").Range(cell).Value
If Len(billNumber) = 0 Then Exit For
For N = 4 To readLastCellNameSheet
cell = "A" & N
'**
billNumberNamesheet = ExecutiveWorkBook.Worksheets("Summary").Range(cell).Value
If Len(billNumberNamesheet) = 0 Then Exit For
If billNumberNamesheet = billNumber Then
cell = "R" & N & ":" & "AX" & N
copycell = "R" & x & ":" & "AX" & x
ExecutiveWorkBook.Worksheets("Summary").Range(cell).Copy
ThisWorkbook.Worksheets("Master").Range(copycell).PasteSpecial Paste:=xlPasteAll
End If
Next N
Next x
我的代码应该将整行(20列中的一列具有公式)复制到另一个工作簿中。所以错误弹出是因为有一个公式等于错误(#N / A),(#错误)?
无论公式是否等于错误,我都需要复制。主工作簿中的格式将纠正该错误。