VBA with Multiple Table array

Raiden

New Member
Joined
Jun 2, 2022
Messages
26
Office Version
  1. 2021
  2. 2019
Platform
  1. Windows
I'm working on a project which contains multiple columns containing Batch no.& their Quantities.
I have used a VBA code which helps me automatically input the Batch Qty.

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
        
'       Check to see if "Product_In" entry made in column G
        If Target.Column = 10 And Target.Offset(0, -3).Value = "Product_In" Then
            Application.EnableEvents = False
'           Lookup value from Batch Register sheet and place in column J
            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)
'           Limit entry to maximum allowed
            If Target.Value And nx <> Target.Value Then
                MsgBox "Value in Batch card Register does not match" & VBA.Constants.vbNewLine & "Orginal Value will be Entered", 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
'           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(Target.Offset(0, -6), Sheets("FG Register").Columns("D:I"), 6, False)
'           Limit entry to maximum allowed
            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

So i want to update the 'Product_In' Range of Vlookup for Multiple columns i.e. D:E, K:L, R:S, Y:Z etc

Is their a way to do that??
Any help is appreciated
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying

Forum statistics

Threads
1,223,908
Messages
6,175,305
Members
452,633
Latest member
DougMo

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