LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Multiple selection on dropdown in same cell

Try this in the code behind the worksheet...

Option Explicit

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Count = 1 Then
If Target.Column = 8 Then sub1_Change Target
If Target.Column = 11 Then sub2_Change Target
End If 'Target.Count = 1
End Sub


Private Sub sub1_Change(Target As Range)
' Description of what this does goes here...

Dim sOldVal$, sNewVal, lCode&
Dim rngDV As Range, rngList As Range, rngListID As Range

With ActiveSheet
Set rngList = .Range("external")
Set rngListID = .Range("externalID")
End With 'ActiveSheet

'On Error Resume Next
Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
If rngDV Is Nothing Then Exit Sub

On Error GoTo exitHandler
If Not Intersect(Target, rngDV) Is Nothing Then
Application.EnableEvents = False
With Target
sNewVal = .Value: Application.Undo
sOldVal = .Value: .Value = sNewVal
If sNewVal = "" Then .Offset(0, 1).ClearContents
End With 'Target
With rngListID.Range("A1")
If Not oldVal = "" Then
lCode = .Offset(WorksheetFunction.Match(Target.Value, rngList,
0) - 1, 0)
Target.Offset(0, 1).Value = lCode
Else
lCode = .Offset(WorksheetFunction.Match(Target.Value, rngList,
0) - 1, 0)
Target.Value = sOldVal & ", " & sNewVal
Target.Offset(0, 1).Value = Target.Offset(0, 1).Value & ", " &
lCode
End If 'Not oldVal = ""
End With 'rngListID.Range("A1")
End If 'Not Intersect(Target, rngDV) Is Nothing

exitHandler:
Application.EnableEvents = True
End Sub

Private Sub sub2_Change(Target As Range)
' Description of what this does goes here...

Dim rngDV As Range, sOldVal$, sNewVal$

Set rngDV = Cells.SpecialCells(xlCellTypeAllValidation)
If rngDV Is Nothing Then Exit Sub

If Not Intersect(Target, rngDV) Is Nothing Then
Application.EnableEvents = False
With Target
sNewVal = .Value: Application.Undo
sOldVal = .Value: .Value = sNewVal
If sOldVal < "" Or sNewVal < "" Then _
.Value = oldVal & ", " & newVal
End With 'Target
End If 'Not Intersect(Target, rngDV) Is Nothing

exitHandler:
Application.EnableEvents = True
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
Classic VB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I allow a multiple selection from a dropdown? Monica Excel Discussion (Misc queries) 11 April 17th 08 04:34 PM
Dropdown in cell base on a selection of a different drop down paapa21 Excel Programming 3 February 26th 08 11:52 PM
How do you lock a cell after making a selection from a dropdown b GuyHUf Excel Worksheet Functions 0 June 25th 07 04:06 PM
VLOOKUP or dropdown in the cell depending on selection in another Spottydog Excel Discussion (Misc queries) 1 January 31st 07 07:59 AM
Allow selection of multiple values in dropdown list in excel Nancy @ CHR Excel Discussion (Misc queries) 2 April 13th 06 10:44 PM


All times are GMT +1. The time now is 08:24 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"