嗨,伙计们,我是宏 excel 的新手,我试图将某个工作簿中的值复制到另一个工作簿,现在我遇到了代码中的错误,我找不到解决方案,我已经在互联网上进行了一些研究以找到解决方案错误任务,但最终没有解决方案。错误在于“if”语法我不明白,因为我想我已经正确地编写了语法,但错误总是出现在那里。
所以这是我的 vba 代码。
Sub copy()
Dim wsCopy As Worksheet
Dim wsDest As Worksheet
Dim wsCopyT As Worksheet
Dim lCopyLastRow As Long
Dim lDestLastRow As Long
Dim a As Long
Dim b As Long
Set wsCopy = Workbooks("DNWID0162019011613-DOWID190115AM.xls").Worksheets("DNOZA0012015110201")
Set wsDest = Workbooks("macro template.xlsm").Worksheets("Sheet1")
Set wsCopyT = Workbooks("macro template.xlsm").Worksheets("Template")
Set wsDestI = Workbooks("macro template.xlsm").Worksheets("Stock on Hand")
lCopyLastRow = wsCopy.Cells(wsCopy.Rows.Count, "B").End(xlUp).Row
lDestLastRow = wsDest.Cells(wsDest.Rows.Count, "B").End(xlUp).Offset(1).Row
a = wsCopy.Cells(wsCopy.Rows.Count, "B").End(xlUp).Row
b = wsDestI.Cells(wsCopy.Rows.Count, "G").End(xlUp).Row
For i = 1 To (a)
If wsCopy.Cells("E" & 9 + i).Value = "" Then
For s = 4 To b
If wsCopy.Cells("B" & 9 + i).Value = wsDestI.Cells("G" & s).Value Then
wsDestI.Cells("G" & s).copy
wsDest.Cells("S" & lDestLastRow).PasteSpecial Paste:=xlPasteValues
wsDestI.Cells("C" & s).copy
wsDest.Cells("M" & lDestLastRow).PasteSpecial Paste:=xlPasteValues
wsDestI.Cells("M" & s).copy
wsDest.Cells("P" & lDestLastRow).PasteSpecial Paste:=xlPasteValues
End If
Next s
Else: wsCopy.Cells("E" & 9 + i).copy
wsDest.Cells("M" & lDestLastRow).PasteSpecial Paste:=xlPasteValues
wsCopy.Cells("K" & 9 + i).copy
wsDest.Cells("P" & lDestLastRow).PasteSpecial Paste:=xlPasteValues
End If
Next i
wsDest.Range("M2:M" & lDestLastRow).Select
Dim max_baris As Long
max_baris = wsDest.Range("M2").End(xlDown).Row
For d = 2 To (max_baris)
wsCopy.Cells("E2").copy
wsDest.Cells("B" & d).PasteSpecial Paste:=xlPasteValues
wsCopy.Cells("E3").copy
wsDest.Cells("AB" & d).PasteSpecial Paste:=xlPasteValues
wsCopy.Cells("E6").copy
wsDest.Cells("AC" & d).PasteSpecial Paste:=xlPasteValues
'wsDest.Range("L" & i + 1) = i
If wsCopy.Range("B" & 8 + d) = ("") Then
wsDest.Range("S" & d) = ("0")
Else
wsCopy.Range("B" & 9 + d).copy
wsDest.Range("S" & d).PasteSpecial Paste:=xlPasteValues
End If
wsCopyT.Cells("A2").copy wsDest.Cells("A" & d)
wsCopyT.Cells("C2").copy wsDest.Cells("C" & d)
wsCopyT.Cells("J2").copy wsDest.Cells("J" & d)
wsCopyT.Cells("J2").copy wsDest.Cells("K" & d)
wsCopyT.Cells("Q2").copy wsDest.Cells("Q" & d)
wsCopyT.Cells("R2").copy wsDest.Cells("R" & d)
wsCopyT.Cells("AE2").copy wsDest.Cells("AE" & d)
wsCopyT.Cells("AG2").copy wsDest.Cells("AG" & d)
wsCopyT.Cells("AI2").copy wsDest.Cells("AI" & d)
Next d
End Sub
有什么建议吗?谢谢你
如果错误出现在一行:
如果 wsCopy.Range("B" & 8 + d) = ("")
您可以将其替换为:
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句