So i have this VBA code running which Verifies in the given column whether it is "Product_In" or "Dispatch".
If its "Product_In", it paste the value of the batch no. present in the Batch card Register & If its "Dispatch", i have setup a limiter so that whenever i put a Qty and if that qty exceeds the present qty it shows an error and resets the value to present value.
So just like that of "Dispatch", can we change the "Product_In" code just like that of the "Dispatch" code.
I will also attach the file which contains the code so you will understand the mechanism. Here easyupload.io
If its "Product_In", it paste the value of the batch no. present in the Batch card Register & If its "Dispatch", i have setup a limiter so that whenever i put a Qty and if that qty exceeds the present qty it shows an error and resets the value to present value.
So just like that of "Dispatch", can we change the "Product_In" code just like that of the "Dispatch" code.
I will also attach the file which contains the code so you will understand the mechanism. Here easyupload.io
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim check
Dim cl As Range
Dim mx As Double
Dim batch
Dim rng As Range
ActiveSheet.Unprotect "FGIM@22"
For Each cl In Target.Cells
' Check to see if "Product_In" entry made in column G
If Target.Column = 7 And Target.Value = "Product_In" Then
Application.EnableEvents = False
' Lookup value from Batch Register sheet and place in column H
Target.Offset(0, 1).FormulaR1C1 = "=SUMIFS('Batch Register'!C[-2],'Batch Register'!C[-3],Product Log_In!RC[-1],'Batch Register'!C[-4],Product Log_In!RC[-3])"
Application.EnableEvents = True
End If
' Verify entry in column H when "Dispatch" in is column G
If Target.Column = 10 And Target.Offset(0, -3).Value = "Dispatch" Then
Application.EnableEvents = False
' Lookup value maximum allowable value from "FG Register" sheet
batch = Target.Offset(0, -6)
Set rng = Sheets("FG Register").Columns("D:I")
mx = Application.WorksheetFunction.VLookup(batch, rng, 6, 0)
' Limit entry to maximum allowed
If Target.Value And mx < 0 Then
MsgBox "Value in column H 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("B" & cl.Row & ":H" & cl.Row).Locked = False
End If
End If
Next cl
ActiveSheet.Unprotect "FGIM@22"
If Not Intersect(Target, Me.Range("A1:AA1000")) Is Nothing Then
ThisWorkbook.Save
End If
End Sub