VBA multi-select dropdown menu help

ryansm05

Board Regular
Joined
Sep 14, 2016
Messages
148
Office Version
  1. 365
Platform
  1. Windows
Hi,

I have the below code, which enables me to select multiple options from a drop-down menu.

However, I want to amend this to column I, J and K - but the code is not letting me go any further than I37 (it goes red). This does coincide when it moves to the next line if this could be the issue?

If anyone can help me it'd be much appreciated!

PHP:
Private Sub Worksheet_Change(ByVal Target As Range)
'Code by Sumit Bansal from https://trumpexcel.com' To make mutliple selections in a Drop Down List in Excel
Dim Oldvalue As StringDim Newvalue As String
On Error GoTo ExitsubIf Target.Address = "$H$2" Or Target.Address = "$H$3" Or Target.Address = "$H$4" Or Target.Address = "$H$5" Or Target.Address = "$H$6" Or Target.Address = "$H$7" Or Target.Address = "$H$8" Or Target.Address = "$H$9" Or Target.Address = "$H$10" Or Target.Address = "$H$11" Or Target.Address = "$H$12" Or Target.Address = "$H$13" Or Target.Address = "$H$14" Or Target.Address = "$H$15" Or Target.Address = "$H$16" Or Target.Address = "$H$17" Or Target.Address = "$H$18" Or Target.Address = "$H$19" Or Target.Address = "$H$20" Or Target.Address = "$H$21" Or Target.Address = "$H$22" Or Target.Address = "$H$23" Or Target.Address = "$H$24" Or Target.Address = "$H$25" Or Target.Address = "$H$26" Or Target.Address = "$H$27" Or Target.Address = "$H$28" Or Target.Address = "$H$29" Or Target.Address = "$H$30" Or Target.Address = "$H$31" Or Target.Address = "$H$32" Or Target.Address = "$H$33" Or Target.Address = "$H$34" Or Target.Address = "$H$35" Or Target.Address = "$H$36" Or Target.Address = "$H$37" Then
    If Target.SpecialCells(xlCellTypeAllValidation) Is Nothing Then    GoTo Exitsub    Else: If Target.Value = "" Then GoTo Exitsub Else        Application.EnableEvents = False        Newvalue = Target.Value        Application.Undo        Oldvalue = Target.Value        If Oldvalue = "" Then            Target.Value = Newvalue        Else            Target.Value = Oldvalue & ", " & Newvalue        End If    End IfEnd IfApplication.EnableEvents = TrueExitsub:Application.EnableEvents = TrueEnd Sub
 
Last edited:

Excel Facts

Select all contiguous cells
Pressing Ctrl+* (asterisk) will select the "current region" - all contiguous cells in all directions.
Replace the line with all the Target.Address with
Code:
If Not Intersect(Target, Range("H3:K37")) Is Nothing Then
 
Upvote 0

Forum statistics

Threads
1,223,229
Messages
6,170,881
Members
452,364
Latest member
springate

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