ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   drop down deletion errors (https://www.excelbanter.com/excel-programming/431616-drop-down-deletion-errors.html)

Tech_Wolf[_2_]

drop down deletion errors
 
I am currently running a macro to allow me to select more than one item from
a drop down list, however after all the selections are made, if I try to go
in to the cell and erase one, it displays an error and will not let me do so.
I suspect it has something to do with the fact that the cell is formatted as
a list in the data validation tab, but I am not sure how to work around that.

Here is the code I am currently running, in case it helps.

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 = 5 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



ryguy7272

drop down deletion errors
 
Sound like the behavior of an array. Maybe you should consider an
alternative. Take a look at this:
http://www.dailydoseofexcel.com/arch...ect-listboxes/

HTH,
Ryan---

--
Ryan---
If this information was helpful, please indicate this by clicking ''Yes''.


"Tech_Wolf" wrote:

I am currently running a macro to allow me to select more than one item from
a drop down list, however after all the selections are made, if I try to go
in to the cell and erase one, it displays an error and will not let me do so.
I suspect it has something to do with the fact that the cell is formatted as
a list in the data validation tab, but I am not sure how to work around that.

Here is the code I am currently running, in case it helps.

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 = 5 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




All times are GMT +1. The time now is 04:57 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com