PurplePlop
New Member
- Joined
- May 4, 2024
- Messages
- 2
- Office Version
- 365
- Platform
- Windows
I currently have the issue I cannot backspace on the first value in a cell without throwing all other values in the cell off. This seems to happen when the cell only has 2 values - a Stop Alert I’ve called ‘User Error’ (using Data Validation) is not thrown either. I’m trying to standardize things as much as possible.
How can I stop this from happening?
code:
How can I stop this from happening?
code:
VBA Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Const SEPARATOR As String = "/ "
Dim Oldvalue As String
Dim Newvalue As String
On Error GoTo Exitsub
If Not Intersect(Target, Range("C:C, D:D, E:E, G:G")) Is Nothing Then
If Not Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then
If Target.Value <> "" Then
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 & SEPARATOR & Newvalue
Else
Dim parts() As String
parts = Split(Oldvalue, SEPARATOR)
Dim n As Long
For n = LBound(parts) To UBound(parts)
If parts(n) = Newvalue Then
parts(n) = "|#|"
Exit For
End If
Next n
Target.Value = Join(Filter(parts, "|#|", False), SEPARATOR)
End If
End If
End If
End If
End If
Exitsub:
Application.EnableEvents = True
End Sub