I have two sheets, the first pulls the data from the second to print out later.
I have three scripts on the first sheet. Print, Edit Update.
Print works flawlessly.
Edit works flawlessly.
Update is where my issue is.
When I update the form, four cells dance, their data changes without me making any changes on the sheet.
The first two are B17 and B20.
The second are Q23 and R25.
The problem is that the jumping of data is between all four cells. the Sales Order may jump to Part Revision, and the Part ID jumps to Sales order, and sometimes Sales Order jumps to NCMR Qty.
I can’t figure out why this is happening. The VBA code looks solid, can someone not only verify this is going on in their computer, but perhaps why it is happening?
Here is the sheet:
http://dl.dropbox.com/u/3327208/Excel/Edit%26Update.xlsm
Here is the code that is causing the problem.
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
I am now getting an error here.
P(i + 1).Value = wsPE.Range(c(i)).Value
Error occurs because you have a blank space in array C at the 5th element.
Get rid of that and it will work. I just did and ran it flawlessly.