The below code is for VLOOKUP result in same cell, which is working well, but now I also need VLOOKUP values for Range("K:L"), (R:S) and further.
My vlookup formula is this :
Result I need: If i type the Qty in Cl no 10, it will verify the value from the other sheet based on the 'batch'. The column index no for all the ranges is same i.e. 2
Example: If i type 100 in Cl no 10, it will verify in the "Batch Card Register" whether the value of the mentioned batch is 100 or not. If value is not 100 i have added a code so it will return the original value which is 90.
My vlookup formula is this :
VBA Code:
nx = Application.WorksheetFunction.VLookup(batch, Sheets("Batch Card REGISTER").Range("D:E"), 2, False)
Result I need: If i type the Qty in Cl no 10, it will verify the value from the other sheet based on the 'batch'. The column index no for all the ranges is same i.e. 2
Example: If i type 100 in Cl no 10, it will verify in the "Batch Card Register" whether the value of the mentioned batch is 100 or not. If value is not 100 i have added a code so it will return the original value which is 90.
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim check
Dim cl As Range
Dim mx As Double
Dim nx As Double
Dim batch
Dim rng As Range
Dim Rg As Range
ActiveSheet.Unprotect "FGIM@22"
For Each cl In Target.Cells
If Target.Column = 10 And Target.Offset(0, -3).Value = "Product_In" Then
Application.EnableEvents = False
batch = Target.Offset(0, -6)
Set Rg = Sheets("Batch Card REGISTER").Range("D:E")
nx = Application.WorksheetFunction.VLookup(batch, Sheets("Batch Card REGISTER").Range("D:E"), 2, False)
If Target.Value And nx <> Target.Value Then
MsgBox "NOTE: Value does not Match" & VBA.Constants.vbNewLine & "Orginal Value from Batch Card Register will be Restored", vbOKOnly, "ENTRY ERROR!"
Target.Value = nx
End If
Application.EnableEvents = True
End If
Verify entry in column J when "Dispatch" in is column G
If Target.Column = 10 And Target.Offset(0, -3).Value = "Dispatch" Then
Application.EnableEvents = False
batch = Target.Offset(0, -6)
Set rng = Sheets("FG Register").Columns("D:I")
mx = Application.WorksheetFunction.VLookup(Target.Offset(0, -6), Sheets("FG Register").Columns("D:I"), 6, False)
If Target.Value And mx < 0 Then
MsgBox "Value in Current Stock cannot exceed " & mx, vbOKOnly, "ENTRY ERROR!"
Target.Value = Target.Value + mx
End If
Application.EnableEvents = True
End If
If Target.Column = 10 Then
check = MsgBox("NOTE: CANNOT be edited after confirmation, Confirm the Entry?", vbYesNo, "Confirm Entry")
If check = vbYes Then
Range("A" & cl.Row & ":J" & cl.Row).Locked = True
Else
Range("C" & cl.Row & ":H" & cl.Row).Locked = False
End If
End If
Next cl
If Not Intersect(Target, Me.Range("A1:AA1000")) Is Nothing Then
ThisWorkbook.Save
End If
End Sub