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

Highlight Duplicates
Home, Conditional Formatting, Highlight Cells, Duplicate records, OK to add pink formatting to any duplicates in selected range.

Forum statistics

Threads
1,214,830
Messages
6,121,834
Members
449,051
Latest member
excelquestion515

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