Hi All.....
Making some modifications in my workbook as I have ample time on hand due to lock down.
I have a worksheet change event given below.....i need to replicate the same event three times with different ranges.
Went through alot of threads but could not find one specific to my need....
Please help
The above three code perform exactly the same function but with three different ranges.
I need to combine them in the same Worksheet change event.
Making some modifications in my workbook as I have ample time on hand due to lock down.
I have a worksheet change event given below.....i need to replicate the same event three times with different ranges.
Went through alot of threads but could not find one specific to my need....
Please help
VBA Code:
'Quantity input Box Column Default= "1"
Private Sub Worksheet_Change(ByVal Target As Range)
Const SCAN_CELL As String = "C2"
Const RANGE_BC As String = "B4:B14"
Dim val, f As Range, rngCodes As Range
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range(SCAN_CELL)) Is Nothing Then Exit Sub
val = Trim(Target.Value)
If Len(val) = 0 Then Exit Sub
Set rngCodes = Me.Range(RANGE_BC)
Set f = rngCodes.Find(val, , xlValues, xlWhole)
If Not f Is Nothing Then
With f.Offset(0, 3)
.Value = .Value + 1
End With
Else
Set f = rngCodes.Cells(rngCodes.Cells.Count).End(xlUp).Offset(1, 0)
f.Value = val
f.Offset(0, 3).Value = 1
End If
Application.EnableEvents = False
Target.Value = ""
Application.EnableEvents = True
Target.Select
End Sub
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Const SCAN_CELL As String = "JC2"
Const RANGE_BC As String = "JB4:JB14"
Dim val, f As Range, rngCodes As Range
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range(SCAN_CELL)) Is Nothing Then Exit Sub
val = Trim(Target.Value)
If Len(val) = 0 Then Exit Sub
Set rngCodes = Me.Range(RANGE_BC)
Set f = rngCodes.Find(val, , xlValues, xlWhole)
If Not f Is Nothing Then
With f.Offset(0, 3)
.Value = .Value + 1
End With
Else
Set f = rngCodes.Cells(rngCodes.Cells.Count).End(xlUp).Offset(1, 0)
f.Value = val
f.Offset(0, 3).Value = 1
End If
Application.EnableEvents = False
Target.Value = ""
Application.EnableEvents = True
Target.Select
End Sub
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Const SCAN_CELL As String = "KC2"
Const RANGE_BC As String = "KB4:KB14"
Dim val, f As Range, rngCodes As Range
If Target.Cells.Count > 1 Then Exit Sub
If Intersect(Target, Me.Range(SCAN_CELL)) Is Nothing Then Exit Sub
val = Trim(Target.Value)
If Len(val) = 0 Then Exit Sub
Set rngCodes = Me.Range(RANGE_BC)
Set f = rngCodes.Find(val, , xlValues, xlWhole)
If Not f Is Nothing Then
With f.Offset(0, 3)
.Value = .Value + 1
End With
Else
Set f = rngCodes.Cells(rngCodes.Cells.Count).End(xlUp).Offset(1, 0)
f.Value = val
f.Offset(0, 3).Value = 1
End If
Application.EnableEvents = False
Target.Value = ""
Application.EnableEvents = True
Target.Select
End Sub
The above three code perform exactly the same function but with three different ranges.
I need to combine them in the same Worksheet change event.