Delete specific selection in multiple selection Drop Down list in VB

Duette

New Member
Joined
Feb 19, 2009
Messages
17
I've been trying to find a way to use the MID and LEN functions in VB. I have an Excel 2003 spreadsheet that uses multiple dropdown selections placed in one cell. What I would like to do is every time the user accidentally selects something that has already been put in the cell it returns nothing, as opposed to placing a duplicate in the cell. When there are duplicates there's nothing you can do but delete the entire cell and start over with your selections. Here's my code:

Rich (BB code):
Option Explicit
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 = 3 Then
    If oldVal = "" Then
      'do nothing
      ElseIf newVal = Application.WorksheetFunction.Mid(oldVal, _
      Application.WorksheetFunction.Find(newVal, oldVal), _
      Application.WorksheetFunction.Len(oldVal)) Then
      'do nothing
      ElseIf newVal = "" Then
      'do nothing
      Else
      Target.Value = oldVal & "," & Chr(10) & newVal
      End If
  End If
End If
exitHandler:
  Application.EnableEvents = True
End Sub

The line of code that gets tripped is bolded. Any suggestions?
 

Excel Facts

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.

Forum statistics

Threads
1,223,236
Messages
6,170,912
Members
452,366
Latest member
TePunaBloke

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top