Hello to everybody
I have found the below very useful code from Contextures Excel Resources to Help You Succeed
Please notice the part where it states for which column we get this function. In this example the code works for column 6 or F
What I need to have, is to make it work for multiple columns, lets say column 7 & 8 (or G & H)
Is this feat possible??
Thank you in advance
I have found the below very useful code from Contextures Excel Resources to Help You Succeed
VBA Code:
Option Explicit
' Developed by Contextures Inc.
' www.contextures.com
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
Dim strVal As String
Dim i As Long
Dim lCount As Long
Dim Ar As Variant
On Error Resume Next
Dim lType As Long
If Target.Count > 1 Then GoTo exitHandler
lType = Target.Validation.Type
If lType = 3 Then
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If Target.Column = 6 Then
If oldVal = "" Then
'do nothing
Else
If newVal = "" Then
'do nothing
Else
On Error Resume Next
Ar = Split(oldVal, ", ")
strVal = ""
For i = LBound(Ar) To UBound(Ar)
Debug.Print strVal
Debug.Print CStr(Ar(i))
If newVal = CStr(Ar(i)) Then
'do not include this item
strVal = strVal
lCount = 1
Else
strVal = strVal & CStr(Ar(i)) & ", "
End If
Next i
If lCount > 0 Then
Target.Value = Left(strVal, Len(strVal) - 2)
Else
Target.Value = strVal & newVal
End If
End If
End If
End If
End If
exitHandler:
Application.EnableEvents = True
End Sub
Please notice the part where it states for which column we get this function. In this example the code works for column 6 or F
VBA Code:
Target.Value = newVal
If Target.Column = 6 Then
If oldVal = "" Then
'do nothing
What I need to have, is to make it work for multiple columns, lets say column 7 & 8 (or G & H)
Is this feat possible??
Thank you in advance