glamourphotographer
New Member
- Joined
- Jun 23, 2015
- Messages
- 6
I have a range of cells in a column, in an Excel spreadsheet. Each cell contains the same drop down list, containing the same "items" to choose from. I have a VBA code (below) that allows me to choose multiple items from the drop down list, instead of just a single item, but the VBA code will only work in one cell, and won't work over the range of cells. How can I make it work over the whole range of cells in the column? Thank you in advance.
Code:
[FONT=Calibri][SIZE=3][COLOR=#000000]Private Sub Worksheet_Change(ByVal Target As Range)[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]'Code by Sumit Bansal from [/COLOR][/SIZE][/FONT][URL="https://trumpexcel.com/"][FONT=Calibri][SIZE=3][COLOR=#0000ff]https://trumpexcel.com[/COLOR][/SIZE][/FONT][/URL]
[FONT=Calibri][SIZE=3][COLOR=#000000]' To make mutliple selections in a Drop Down List in Excel[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Dim Oldvalue As String[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Dim Newvalue As String[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]On Error GoTo Exitsub[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]If Target.Address = "$C$2" Then[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] If Target.SpecialCells(xlCellTypeAllValidation) IsNothing Then[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] GoTo Exitsub[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Else: If Target.Value = "" Then GoToExitsub Else[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Application.EnableEvents =False[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Newvalue = Target.Value[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Application.Undo[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Oldvalue = Target.Value[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] If Oldvalue = ""Then[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Target.Value = Newvalue[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Else[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] Target.Value = Oldvalue & ", " & Newvalue[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] End If[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000] End If[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]End If[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Application.EnableEvents = True[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Exitsub:[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]Application.EnableEvents = True[/COLOR][/SIZE][/FONT]
[FONT=Calibri][SIZE=3][COLOR=#000000]End Sub[/COLOR][/SIZE][/FONT]
Last edited by a moderator: