VBA Formula Change

Raiden

New Member
Joined
Jun 2, 2022
Messages
26
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
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

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
 

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Forum statistics

Threads
1,214,954
Messages
6,122,461
Members
449,085
Latest member
ExcelError

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top