SanFelippo
Board Regular
- Joined
- Apr 4, 2017
- Messages
- 124
Hello,
I am doing my best to learn and understand VBA coding, and this one particular piece of code I think I have an idea of what it is doing, but I would rather be absolutely sure so I know I understand it completely. Could someone explain what this is doing? It would be great if you could put comments in the code after some of the lines to explain what they are doing, as well as explain overall what the code is doing. Is it some way of making sure not more than one cell is selected or something like that?
Thanks!
I am doing my best to learn and understand VBA coding, and this one particular piece of code I think I have an idea of what it is doing, but I would rather be absolutely sure so I know I understand it completely. Could someone explain what this is doing? It would be great if you could put comments in the code after some of the lines to explain what they are doing, as well as explain overall what the code is doing. Is it some way of making sure not more than one cell is selected or something like that?
Code:
Private Sub Worksheet_Change(ByVal Target As Range)
Dim rngDV As Range
Dim oldVal As String
Dim newVal As String
If Target.Count > 1 Then GoTo exitHandler
On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
On Error GoTo exitHandler
If rngDV Is Nothing Then GoTo exitHandler
If Intersect(Target, rngDV) Is Nothing Then
'do nothing
Else
Application.EnableEvents = False
newVal = Target.Value
Application.Undo
oldVal = Target.Value
Target.Value = newVal
If Target.Column = 24 Then
If oldVal = "" Then
'do nothing
Else
If newVal = "" Then
'do nothing
Else
Target.Value = oldVal _
& ", " & newVal
End If
End If
End If
End If
exitHandler:
Application.EnableEvents = True
End Sub
Thanks!