我正在使用以下代码从以“待办订单详细信息”开头的excel文件中进行复制:
Sub INSERT()
Dim Wb1 As Workbook, wb2 As Workbook, wB As Workbook
Dim rngToCopy As Range
Dim countEND As Long
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Sheets("RAW_DATA").Select
Worksheets("RAW_DATA").Range("A3:CA45000").ClearContents
If ActiveSheet.AutoFilterMode Then ActiveSheet.AutoFilter.ShowAllData
For Each wB In Application.Workbooks
If Left(wB.Name, 17) = "Backorders Detail" Then
Set Wb1 = wB
Exit For
End If
Next
If Not Wb1 Is Nothing Then
Set wb2 = ThisWorkbook
With Wb1.Sheets(2)
Set rngToCopy = .Range("A3:BX3", .Cells(.Rows.Count, "A").End(xlUp))
End With
wb2.Sheets("RAW_DATA").Range("A3:BX3").Resize(rngToCopy.Rows.Count).Value = rngToCopy.Value
End If
With wb2.Sheets("RAW_DATA")
countEND = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("BY3:BY" & countEND).Formula = "=IFERROR(IF(AND(VLOOKUP(VALUE(AS3);BG_DATA!A:A;1;FALSE)=(VLOOKUP(VALUE(AS3);BG_DATA!A:A;1;FALSE));(AF3>0));"""";""x"");""x"")" 'Check
.Range("BZ3:BZ" & countEND).Formula = "=VLOOKUP(VALUE(AS3);BG_DATA!A:I;9;FALSE)" 'Vendor'
.Range("CA3:CA" & countEND).Formula = "=VLOOKUP(VALUE(AS3);BG_DATA!A:J;10;FALSE)" 'Planner
End With
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
MsgBox "DONE!"
End Sub
我从另一个制作的Excel文件复制了此功能。效果很好。但是由于某种原因,以下部分现在给我一个错误:
With wb2.Sheets("RAW_DATA")
countEND = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("BY3:BY" & countEND).Formula = "=IFERROR(IF(AND(VLOOKUP(VALUE(AS3);BG_DATA!A:A;1;FALSE)=(VLOOKUP(VALUE(AS3);BG_DATA!A:A;1;FALSE));(AF3>0));"""";""x"");""x"")" 'Check
.Range("BZ3:BZ" & countEND).Formula = "=VLOOKUP(VALUE(AS3);BG_DATA!A:I;9;FALSE)" 'Vendor'
.Range("CA3:CA" & countEND).Formula = "=VLOOKUP(VALUE(AS3);BG_DATA!A:J;10;FALSE)" 'Planner
End With
运行时错误1004-应用程序定义或对象定义的错误。 我用谷歌搜索,但没有找到解决方案。 Excel文件是XLSX,现在是XLSM。有人可以说出问题所在吗?
答案 0 :(得分:1)
您正在使用分号;
作为公式中的分隔符,但是分隔符取决于您的工作簿的本地化。改用逗号,
:
With wb2.Sheets("RAW_DATA")
countEND = .Cells(.Rows.Count, "A").End(xlUp).Row
.Range("BY3:BY" & countEND).Formula = "=IFERROR(IF(AND(VLOOKUP(VALUE(AS3),BG_DATA!A:A,1,FALSE)=(VLOOKUP(VALUE(AS3),BG_DATA!A:A,1,FALSE)),(AF3>0)),"""",""x""),""x"")" 'Check
.Range("BZ3:BZ" & countEND).Formula = "=VLOOKUP(VALUE(AS3),BG_DATA!A:I,9,FALSE)" 'Vendor'
.Range("CA3:CA" & countEND).Formula = "=VLOOKUP(VALUE(AS3),BG_DATA!A:J,10,FALSE)" 'Planner
End With
或者,您可以使用.FormulaLocal
代替.Formula
,但是它仅在本地化将分号定义为分隔符的工作簿中有效。