VBA Code not working for full colum multiple selecton Drop-down list

Leicester City Fox

Board Regular
Joined
Oct 7, 2016
Messages
91
Office Version
  1. 2019
Platform
  1. Windows
Hi there

Need some help I put the vba in for a cell to select multiple drop down options and it works :).

But when I change it so you can do this to the whole column it don't work and it still only work in the original cell.

Its Column T which is Column number 20 but start in cell T8:

Sub DropSelMult()


Dim Oldvalue As String
Dim Newvalue As String

On Error GoTo Exitsub
If Target.Column = 20 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 If
End If
Application.EnableEvents = True
Exitsub:
Application.EnableEvents = True
End Sub



Any help in order to get this t work

Many Thanks

Leicester Fox
 

Excel Facts

Create a chart in one keystroke
Select the data and press Alt+F1 to insert a default chart. You can change the default chart to any chart type
You need to have the code in a Worksheet Event as below.
Also ensure That the Application.EnableEvents , in code, is set to true.
If unsure run a bit of code as below:-
Code:
Private [COLOR="Navy"]Sub[/COLOR] Worksheet_Change(ByVal Target [COLOR="Navy"]As[/COLOR] Range)
[COLOR="Navy"]Dim[/COLOR] Oldvalue [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]
 [COLOR="Navy"]Dim[/COLOR] Newvalue [COLOR="Navy"]As[/COLOR] [COLOR="Navy"]String[/COLOR]

 [COLOR="Navy"]On[/COLOR] [COLOR="Navy"]Error[/COLOR] GoTo Exitsub
 [COLOR="Navy"]If[/COLOR] Target.Column = 20 [COLOR="Navy"]Then[/COLOR]
 [COLOR="Navy"]If[/COLOR] Target.SpecialCells(xlCellTypeAllValidation) [COLOR="Navy"]Is[/COLOR] Nothing [COLOR="Navy"]Then[/COLOR]
GoTo Exitsub
Else: [COLOR="Navy"]If[/COLOR] Target.Value = "" [COLOR="Navy"]Then[/COLOR] GoTo Exitsub [COLOR="Navy"]Else[/COLOR]
Application.EnableEvents = False
Newvalue = Target.Value
Application.Undo
Oldvalue = Target.Value
[COLOR="Navy"]If[/COLOR] Oldvalue = "" [COLOR="Navy"]Then[/COLOR]
Target.Value = Newvalue
[COLOR="Navy"]Else[/COLOR]
Target.Value = Oldvalue & ", " & Newvalue
[COLOR="Navy"]End[/COLOR] If
[COLOR="Navy"]End[/COLOR] If
 [COLOR="Navy"]End[/COLOR] If
 Application.EnableEvents = True
Exitsub:
 Application.EnableEvents = True
 [COLOR="Navy"]End[/COLOR] [COLOR="Navy"]Sub[/COLOR]


EnableEvent Code:-
Code:
Private Sub CommandButton1_Click()
Application.EnableEvents = True
End Sub

Regards Mick
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,181
Members
453,022
Latest member
Mohamed Magdi Tawfiq Emam

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