Hi guys,
I have a VBA script that takes data from two workbooks, modifies them and puts them into a third workbook. However at some point in the second loop of the script the process crashes and Excel freezes up. Are thee any ways to speed the script up to make it a little easier on Excel? The initial workbooks are pretty large often around 60K rows. I'm fairly new to VBA so apologies if I've made some massive error in the coding, just worked it out from what I would do manually to the steps.
Any advice would be greatly appreciated. Below is the code.
Many thanks, Dan
I have a VBA script that takes data from two workbooks, modifies them and puts them into a third workbook. However at some point in the second loop of the script the process crashes and Excel freezes up. Are thee any ways to speed the script up to make it a little easier on Excel? The initial workbooks are pretty large often around 60K rows. I'm fairly new to VBA so apologies if I've made some massive error in the coding, just worked it out from what I would do manually to the steps.
Any advice would be greatly appreciated. Below is the code.
Public Sub CommandButton1_Click()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim RowNumber As Long
Dim BORowNumber As Long
Dim INCRowNumber As Long
Dim BODoc As Variant, BOwb As Workbook
Dim INCDoc As Variant, INCwb As Workbook
Dim PDwb As String
RowNumber = CLng(1)
BORowNumber = CLng(4)
INCRowNumber = CLng(1)
PDwb = ThisWorkbook.Name
MsgBox ("Enter an INC Docment")
INCDoc = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLSX), *.XLSX", Title:="Select File To Be Opened")
If INCDoc = False Then Exit Sub
Set INCwb = Workbooks.Open(INCDoc)
INCwb.Sheets("Stock").Select
Do Until IsEmpty(ActiveCell)
RowNumber = RowNumber + 1
INCRowNumber = INCRowNumber + 1
Workbooks(PDwb).Sheets("pivotdata").Range("B" & RowNumber).Value = "INC"
Workbooks(PDwb).Sheets("pivotdata").Range("K" & RowNumber & ":P" & RowNumber).Value = "0"
Workbooks(PDwb).Sheets("pivotdata").Range("Q" & RowNumber).Value = INCwb.Sheets("Stock").Range("K" & INCRowNumber).Value
Workbooks(PDwb).Sheets("pivotdata").Range("R" & RowNumber).Value = INCwb.Sheets("Stock").Range("M" & INCRowNumber).Value
Workbooks(PDwb).Sheets("pivotdata").Range("S" & RowNumber).Value = Workbooks(PDwb).Sheets("pivotdata").Range("Q" & RowNumber).Value + _
Workbooks(PDwb).Sheets("pivotdata").Range("R" & RowNumber).Value
Workbooks(PDwb).Sheets("pivotdata").Range("T" & RowNumber).Value = INCwb.Sheets("Stock").Range("L" & INCRowNumber).Value
Workbooks(PDwb).Sheets("pivotdata").Range("U" & RowNumber).Value = INCwb.Sheets("Stock").Range("N" & INCRowNumber).Value
Workbooks(PDwb).Sheets("pivotdata").Range("V" & RowNumber).Value = Workbooks(PDwb).Sheets("pivotdata").Range("T" & RowNumber).Value + _
Workbooks(PDwb).Sheets("pivotdata").Range("U" & RowNumber).Value
Workbooks(PDwb).Sheets("pivotdata").Range("J" & RowNumber).Value = Abs(Left(OnlyNums(INCwb.Sheets("Stock").Range("H" & INCRowNumber).Value), 8))
Workbooks(PDwb).Sheets("pivotdata").Range("C" & RowNumber).Value = Abs(Left(OnlyNums(INCwb.Sheets("Stock").Range("B" & INCRowNumber).Value), 8))
Workbooks(PDwb).Sheets("pivotdata").Range("H" & RowNumber).Value = INCwb.Sheets("Stock").Range("D" & INCRowNumber).Value
If INCwb.Sheets("Stock").Range("J" & INCRowNumber).Value = "ON_HAND" Or INCwb.Sheets("Stock").Range("J" & INCRowNumber).Value = "ON HAND" Then
Workbooks(PDwb).Sheets("pivotdata").Range("E" & RowNumber).Value = "ON-HAND"
ElseIf INCwb.Sheets("Stock").Range("J" & INCRowNumber).Value = "ON_HAND" Then
Workbooks(PDwb).Sheets("pivotdata").Range("E" & RowNumber).Value = "IN-TRANSIT"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("E" & RowNumber).Value = Cell
End If
If (IsError(Application.VLookup(INCwb.Sheets("Stock").Range("C" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$B$2:$C$13"), 2, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("D" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("D" & RowNumber).Value = _
Application.VLookup(INCwb.Sheets("Stock").Range("C" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$B$2:$C$13"), 2, False)
End If
If (IsError(Application.VLookup(INCwb.Sheets("Stock").Range("D" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$H$1:$M$200"), 3, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("F" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("F" & RowNumber).Value = _
Application.VLookup(INCwb.Sheets("Stock").Range("D" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$H$1:$M$200"), 3, False)
End If
If (IsError(Application.VLookup(INCwb.Sheets("Stock").Range("D" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$H$1:$M$200"), 4, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("G" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("G" & RowNumber).Value = _
Application.VLookup(INCwb.Sheets("Stock").Range("D" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$H$1:$M$200"), 4, False)
End If
If (IsError(Application.VLookup(INCwb.Sheets("Stock").Range("D" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$H$1:$M$200"), 6, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("I" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("I" & RowNumber).Value = _
Application.VLookup(INCwb.Sheets("Stock").Range("D" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$H$1:$M$200"), 6, False)
End If
Workbooks(PDwb).Sheets("pivotdata").Range("A" & RowNumber).Value = Workbooks(PDwb).Sheets("pivotdata").Range("D" & RowNumber).Value _
& Workbooks(PDwb).Sheets("pivotdata").Range("E" & RowNumber).Value & Workbooks(PDwb).Sheets("pivotdata").Range("J" & RowNumber).Value
ActiveCell.Offset(1, 0).Select
Loop
INCwb.Close savechanges:=False
MsgBox ("Enter a BO Docment")
BODoc = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLSX), *.XLSX", Title:="Select File To Be Opened")
If BODoc = False Then Exit Sub
Set BOwb = Workbooks.Open(BODoc)
BOwb.Sheets("Stock Reconciliation").Range("B5").Select
Do Until IsEmpty(ActiveCell)
RowNumber = RowNumber + 1
BORowNumber = BORowNumber + 1
Workbooks(PDwb).Sheets("pivotdata").Range("B" & RowNumber).Value = "EDW"
Workbooks(PDwb).Sheets("pivotdata").Range("Q" & RowNumber & ":V" & RowNumber).Value = "0"
Workbooks(PDwb).Sheets("pivotdata").Range("K" & RowNumber & ":P" & RowNumber).Value = BOwb.Sheets("Stock Reconciliation").Range("I" & BORowNumber & ":N" & BORowNumber).Value
Workbooks(PDwb).Sheets("pivotdata").Range("J" & RowNumber).Value = Abs(Left(OnlyNums(BOwb.Sheets("Stock Reconciliation").Range("G" & BORowNumber).Value), 8))
Workbooks(PDwb).Sheets("pivotdata").Range("C" & RowNumber).Value = Abs(Left(OnlyNums(BOwb.Sheets("Stock Reconciliation").Range("E" & BORowNumber).Value), 8))
Workbooks(PDwb).Sheets("pivotdata").Range("H" & RowNumber).Value = Mid(BOwb.Sheets("Stock Reconciliation").Range("F" & BORowNumber).Value, 4, 3)
If BOwb.Sheets("Stock Reconciliation").Range("H" & BORowNumber).Value = "ON_HAND" Or BOwb.Sheets("Stock Reconciliation").Range("H" & BORowNumber).Value = "ON HAND" Then
Workbooks(PDwb).Sheets("pivotdata").Range("E" & RowNumber).Value = "ON-HAND"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("E" & RowNumber).Value = Cell
End If
If (IsError(Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("D" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$B$2:$C$84"), 2, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("D" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("D" & RowNumber).Value = _
Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("D" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$B$2:$C$84"), 2, False)
End If
If (IsError(Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("F" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$I:$N"), 2, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("F" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("F" & RowNumber).Value = _
Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("F" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$I:$N"), 2, False)
End If
If (IsError(Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("F" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$I:$N"), 3, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("G" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("G" & RowNumber).Value = _
Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("F" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$I:$N"), 3, False)
End If
If (IsError(Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("F" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$I:$N"), 5, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("I" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("I" & RowNumber).Value = _
Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("F" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$I:$N"), 5, False)
End If
Workbooks(PDwb).Sheets("pivotdata").Range("A" & RowNumber).Value = Workbooks(PDwb).Sheets("pivotdata").Range("D" & RowNumber).Value _
& Workbooks(PDwb).Sheets("pivotdata").Range("E" & RowNumber).Value & Workbooks(PDwb).Sheets("pivotdata").Range("J" & RowNumber).Value
ActiveCell.Offset(1, 0).Select
Loop
Dim i As Long
Dim x As Long
For i = 2 To INCRowNumber
For x = (INCRowNumber + 1) To (INCRowNumber + BORowNumber)
If Workbooks(PDwb).Sheets("pivotdata").Range("A" & i).Value = Workbooks(PDwb).Sheets("pivotdata").Range("A" & x).Value Then
Workbooks(PDwb).Sheets("pivotdata").Range("W" & i).Value = "In Both"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("W" & i).Value = "In INC - Not in EDW"
End If
Next x
Next i
Dim y As Long
Dim z As Long
For y = (INCRowNumber + 1) To (INCRowNumber + BORowNumber)
For z = 2 To INCRowNumber
If Workbooks(PDwb).Sheets("pivotdata").Range("A" & i).Value = Workbooks(PDwb).Sheets("pivotdata").Range("A" & x).Value Then
Workbooks(PDwb).Sheets("pivotdata").Range("W" & y).Value = "In Both"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("W" & y).Value = "In EDW - Not in INC"
End If
Next z
Next y
BOwb.Close savechanges:=False
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual
Dim RowNumber As Long
Dim BORowNumber As Long
Dim INCRowNumber As Long
Dim BODoc As Variant, BOwb As Workbook
Dim INCDoc As Variant, INCwb As Workbook
Dim PDwb As String
RowNumber = CLng(1)
BORowNumber = CLng(4)
INCRowNumber = CLng(1)
PDwb = ThisWorkbook.Name
MsgBox ("Enter an INC Docment")
INCDoc = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLSX), *.XLSX", Title:="Select File To Be Opened")
If INCDoc = False Then Exit Sub
Set INCwb = Workbooks.Open(INCDoc)
INCwb.Sheets("Stock").Select
Do Until IsEmpty(ActiveCell)
RowNumber = RowNumber + 1
INCRowNumber = INCRowNumber + 1
Workbooks(PDwb).Sheets("pivotdata").Range("B" & RowNumber).Value = "INC"
Workbooks(PDwb).Sheets("pivotdata").Range("K" & RowNumber & ":P" & RowNumber).Value = "0"
Workbooks(PDwb).Sheets("pivotdata").Range("Q" & RowNumber).Value = INCwb.Sheets("Stock").Range("K" & INCRowNumber).Value
Workbooks(PDwb).Sheets("pivotdata").Range("R" & RowNumber).Value = INCwb.Sheets("Stock").Range("M" & INCRowNumber).Value
Workbooks(PDwb).Sheets("pivotdata").Range("S" & RowNumber).Value = Workbooks(PDwb).Sheets("pivotdata").Range("Q" & RowNumber).Value + _
Workbooks(PDwb).Sheets("pivotdata").Range("R" & RowNumber).Value
Workbooks(PDwb).Sheets("pivotdata").Range("T" & RowNumber).Value = INCwb.Sheets("Stock").Range("L" & INCRowNumber).Value
Workbooks(PDwb).Sheets("pivotdata").Range("U" & RowNumber).Value = INCwb.Sheets("Stock").Range("N" & INCRowNumber).Value
Workbooks(PDwb).Sheets("pivotdata").Range("V" & RowNumber).Value = Workbooks(PDwb).Sheets("pivotdata").Range("T" & RowNumber).Value + _
Workbooks(PDwb).Sheets("pivotdata").Range("U" & RowNumber).Value
Workbooks(PDwb).Sheets("pivotdata").Range("J" & RowNumber).Value = Abs(Left(OnlyNums(INCwb.Sheets("Stock").Range("H" & INCRowNumber).Value), 8))
Workbooks(PDwb).Sheets("pivotdata").Range("C" & RowNumber).Value = Abs(Left(OnlyNums(INCwb.Sheets("Stock").Range("B" & INCRowNumber).Value), 8))
Workbooks(PDwb).Sheets("pivotdata").Range("H" & RowNumber).Value = INCwb.Sheets("Stock").Range("D" & INCRowNumber).Value
If INCwb.Sheets("Stock").Range("J" & INCRowNumber).Value = "ON_HAND" Or INCwb.Sheets("Stock").Range("J" & INCRowNumber).Value = "ON HAND" Then
Workbooks(PDwb).Sheets("pivotdata").Range("E" & RowNumber).Value = "ON-HAND"
ElseIf INCwb.Sheets("Stock").Range("J" & INCRowNumber).Value = "ON_HAND" Then
Workbooks(PDwb).Sheets("pivotdata").Range("E" & RowNumber).Value = "IN-TRANSIT"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("E" & RowNumber).Value = Cell
End If
If (IsError(Application.VLookup(INCwb.Sheets("Stock").Range("C" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$B$2:$C$13"), 2, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("D" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("D" & RowNumber).Value = _
Application.VLookup(INCwb.Sheets("Stock").Range("C" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$B$2:$C$13"), 2, False)
End If
If (IsError(Application.VLookup(INCwb.Sheets("Stock").Range("D" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$H$1:$M$200"), 3, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("F" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("F" & RowNumber).Value = _
Application.VLookup(INCwb.Sheets("Stock").Range("D" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$H$1:$M$200"), 3, False)
End If
If (IsError(Application.VLookup(INCwb.Sheets("Stock").Range("D" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$H$1:$M$200"), 4, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("G" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("G" & RowNumber).Value = _
Application.VLookup(INCwb.Sheets("Stock").Range("D" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$H$1:$M$200"), 4, False)
End If
If (IsError(Application.VLookup(INCwb.Sheets("Stock").Range("D" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$H$1:$M$200"), 6, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("I" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("I" & RowNumber).Value = _
Application.VLookup(INCwb.Sheets("Stock").Range("D" & INCRowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$H$1:$M$200"), 6, False)
End If
Workbooks(PDwb).Sheets("pivotdata").Range("A" & RowNumber).Value = Workbooks(PDwb).Sheets("pivotdata").Range("D" & RowNumber).Value _
& Workbooks(PDwb).Sheets("pivotdata").Range("E" & RowNumber).Value & Workbooks(PDwb).Sheets("pivotdata").Range("J" & RowNumber).Value
ActiveCell.Offset(1, 0).Select
Loop
INCwb.Close savechanges:=False
MsgBox ("Enter a BO Docment")
BODoc = Application.GetOpenFilename(FileFilter:="Excel Files (*.XLSX), *.XLSX", Title:="Select File To Be Opened")
If BODoc = False Then Exit Sub
Set BOwb = Workbooks.Open(BODoc)
BOwb.Sheets("Stock Reconciliation").Range("B5").Select
Do Until IsEmpty(ActiveCell)
RowNumber = RowNumber + 1
BORowNumber = BORowNumber + 1
Workbooks(PDwb).Sheets("pivotdata").Range("B" & RowNumber).Value = "EDW"
Workbooks(PDwb).Sheets("pivotdata").Range("Q" & RowNumber & ":V" & RowNumber).Value = "0"
Workbooks(PDwb).Sheets("pivotdata").Range("K" & RowNumber & ":P" & RowNumber).Value = BOwb.Sheets("Stock Reconciliation").Range("I" & BORowNumber & ":N" & BORowNumber).Value
Workbooks(PDwb).Sheets("pivotdata").Range("J" & RowNumber).Value = Abs(Left(OnlyNums(BOwb.Sheets("Stock Reconciliation").Range("G" & BORowNumber).Value), 8))
Workbooks(PDwb).Sheets("pivotdata").Range("C" & RowNumber).Value = Abs(Left(OnlyNums(BOwb.Sheets("Stock Reconciliation").Range("E" & BORowNumber).Value), 8))
Workbooks(PDwb).Sheets("pivotdata").Range("H" & RowNumber).Value = Mid(BOwb.Sheets("Stock Reconciliation").Range("F" & BORowNumber).Value, 4, 3)
If BOwb.Sheets("Stock Reconciliation").Range("H" & BORowNumber).Value = "ON_HAND" Or BOwb.Sheets("Stock Reconciliation").Range("H" & BORowNumber).Value = "ON HAND" Then
Workbooks(PDwb).Sheets("pivotdata").Range("E" & RowNumber).Value = "ON-HAND"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("E" & RowNumber).Value = Cell
End If
If (IsError(Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("D" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$B$2:$C$84"), 2, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("D" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("D" & RowNumber).Value = _
Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("D" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$B$2:$C$84"), 2, False)
End If
If (IsError(Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("F" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$I:$N"), 2, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("F" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("F" & RowNumber).Value = _
Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("F" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$I:$N"), 2, False)
End If
If (IsError(Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("F" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$I:$N"), 3, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("G" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("G" & RowNumber).Value = _
Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("F" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$I:$N"), 3, False)
End If
If (IsError(Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("F" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$I:$N"), 5, False))) Then
Workbooks(PDwb).Sheets("pivotdata").Range("I" & RowNumber).Value = "*chk*"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("I" & RowNumber).Value = _
Application.VLookup(BOwb.Sheets("Stock Reconciliation").Range("F" & BORowNumber).Value, _
Workbooks(PDwb).Sheets("Ctrl").Range("$I:$N"), 5, False)
End If
Workbooks(PDwb).Sheets("pivotdata").Range("A" & RowNumber).Value = Workbooks(PDwb).Sheets("pivotdata").Range("D" & RowNumber).Value _
& Workbooks(PDwb).Sheets("pivotdata").Range("E" & RowNumber).Value & Workbooks(PDwb).Sheets("pivotdata").Range("J" & RowNumber).Value
ActiveCell.Offset(1, 0).Select
Loop
Dim i As Long
Dim x As Long
For i = 2 To INCRowNumber
For x = (INCRowNumber + 1) To (INCRowNumber + BORowNumber)
If Workbooks(PDwb).Sheets("pivotdata").Range("A" & i).Value = Workbooks(PDwb).Sheets("pivotdata").Range("A" & x).Value Then
Workbooks(PDwb).Sheets("pivotdata").Range("W" & i).Value = "In Both"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("W" & i).Value = "In INC - Not in EDW"
End If
Next x
Next i
Dim y As Long
Dim z As Long
For y = (INCRowNumber + 1) To (INCRowNumber + BORowNumber)
For z = 2 To INCRowNumber
If Workbooks(PDwb).Sheets("pivotdata").Range("A" & i).Value = Workbooks(PDwb).Sheets("pivotdata").Range("A" & x).Value Then
Workbooks(PDwb).Sheets("pivotdata").Range("W" & y).Value = "In Both"
Else
Workbooks(PDwb).Sheets("pivotdata").Range("W" & y).Value = "In EDW - Not in INC"
End If
Next z
Next y
BOwb.Close savechanges:=False
Application.ScreenUpdating = True
Application.Calculation = xlCalculationAutomatic
End Sub
Many thanks, Dan