我有两张纸,第一张从第二张中提取数据以便稍后打印出来。
我在第一张纸上有三个脚本。打印,编辑更新。
打印完美无瑕。
编辑工作完美。
更新是我的问题所在。
当我更新表单时,四个单元格会跳舞,它们的数据会发生变化,而我无需在表单上进行任何更改。
前两个是 B17 和 B20。
第二个是Q23和R25。
问题是数据的跳转是在所有四个单元格之间进行的。Sales Order 可能会跳转到 Part Revision,Part ID 会跳转到 Sales order,有时 Sales Order 会跳转到 NCMR Qty。
我无法弄清楚为什么会这样。VBA 代码看起来很可靠,是否有人不仅可以验证他们的计算机中正在发生这种情况,还可以验证为什么会发生这种情况?
这是单子:
http://dl.dropbox.com/u/3327208/Excel/Edit%26Update.xlsm
这是导致问题的代码。
Option Explicit
Sub PENCMR()
Dim i As Integer
'Internal NCMR
Dim wsPE As Worksheet
Dim wsNDA As Worksheet
Dim c As Variant 'Copy Ranges
Dim P As Range 'Paste Ranges
Application.ScreenUpdating = False
'Setting Sheet
Set wsPE = Sheets("NCMR Output")
Set P = wsPE.Range("A63:V63")
Set wsNDA = Sheets("NCMR Data")
c = Array("AG6", "B11", "B14", "B17", "B20", , "Q23", "B23", "Q11", "Q14", "Q17", "Q20", "Q26", "V23" _
, "V25", "V27", "B32", "B40", "B46", "B52", "D58", "L58", "V58")
For i = LBound(c) To UBound(c)
P(i + 1).Value = wsPE.Range(c(i)).Value
Next
With wsNDA
Dim NR As Long, LR As Long, LC As Long
Dim f As Range
LR = .Range("C" & Rows.Count).End(xlUp).Row
LC = .Cells(2, Columns.Count).End(xlToLeft).Column
NR = LR + 1
Set f = .Range("A3:A" & LR).Find(what:=P.Cells(1).Text, LookIn:=xlValues, lookat:=xlWhole)
If Not f Is Nothing Then
f.Resize(1, P.Cells.Count).Value = P.Value
Else
MsgBox "The data can't be shown, please review the data in question, if no problem can be found please contact the developer"
End If
End With
Range("A63:V63").ClearContents
With wsPE
.Range("B11").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,2,FALSE),"""")"
.Range("B14").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,3,FALSE),"""")"
.Range("B17").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,4,FALSE),"""")"
.Range("B20").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,5,FALSE),"""")"
.Range("B23").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,7,FALSE),"""")"
.Range("Q11").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,8,FALSE),"""")"
.Range("Q14").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,9,FALSE),"""")"
.Range("Q17").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,10,FALSE),"""")"
.Range("Q20").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,11,FALSE),"""")"
.Range("Q23").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,6,FALSE),"""")"
.Range("R26").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,12,FALSE),"""")"
.Range("V23").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,13,FALSE),"""")"
.Range("V25").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,14,FALSE),"""")"
.Range("V27").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,15,FALSE),"""")"
.Range("B32").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,16,FALSE),"""")"
.Range("B40").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,17,FALSE),"""")"
.Range("B46").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,18,FALSE),"""")"
.Range("B52").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,19,FALSE),"""")"
.Range("D58").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,20,FALSE),"""")"
.Range("L58").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,21,FALSE),"""")"
.Range("V58").Formula = "=IFERROR(VLOOKUP($AG$6,'NCMR Data'!$A$2:$Y$999999,22,FALSE),"""")"
End With
Application.ScreenUpdating = True
End Sub
我现在在这里遇到错误。
P(i + 1).Value = wsPE.Range(c(i)).Value