Ruben_A
New Member
- Joined
- Jul 20, 2022
- Messages
- 4
- Office Version
- 365
- 2021
- 2019
- 2011
- 2010
- Platform
- Windows
Hi,
Could someone please help me fix this issue, so I did a VBA code that is below but I just want the VBA code to ONLY take affect in column's D, E, and F but the VBA code is affecting every column. How can I fix this?
Could someone please help me fix this issue, so I did a VBA code that is below but I just want the VBA code to ONLY take affect in column's D, E, and F but the VBA code is affecting every column. How can I fix this?
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim Oldvalue As String
Dim Newvalue As String
Application.EnableEvents = True
On Error GoTo Exitsub
If Range("D999:E999:F999").EntireColumn.Show Then
If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
GoTo Exitsub
Else: If Target.Value = "" Then GoTo Exitsub Else
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
If Oldvalue = "" Then
Target.Value = Newvalue
Else
If InStr(1, Oldvalue, Newvalue) = 0 Then
Target.Value = Oldvalue & ", " & Newvalue
Else:
Target.Value = Oldvalue
End If
End If
End If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub