pls help me in this

gopdeep

Board Regular
Joined
Apr 24, 2012
Messages
94
i've written code select multiple options from dropdown...but that is allowing to select the same option again and again...

here is the code which i've written,,,

Code:
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
Else
Application.EnableEvents = False
newval = target.Value
Application.Undo
oldval = target.Value
target.Value = newval
If target.Column = 7 Then
If oldval = "" Then
Else
If newval = "" Then
Else
target.Value = oldval & "," & newval
End If
End If
End If
End If
exithandler:
Application.EnableEvents = True
End Sub

i've tried like

Code:
If target.Column = 7 Then
If oldval = "" Then
Else
If newval = "" Then
Else
If oldval<>newval Then
target.Value = oldval & "," & newval
Else
MsgBox "Already Selected"
End If
End If
End If
but it doesn't work... can anyone :help: me in this
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
:roll: yeap its working correctly... i tried to insert a msgbox in it where i made mistake... just now only i've found & corrected that... consequently it is working now...

thx a lot
 
Upvote 0
Hello,

I have been following this thread and I have the provided code working. I was wondering if any one can suggest what changes would need to be made to allow this to run in a range of columns rather than just the 7th.

Rather new at macros but I have tried changing the "Target.Column = 7" to something like Target.Column = Range("7:8") or Target.Column = 7,9 but no luck. I would appreciate some help.

Thank You,

Corey.
 
Upvote 0
To consider more columns use something like,
Code:
[FONT="Consolas"][SIZE="2"][COLOR="Navy"]If Target.Column = 7 Or _
    Target.Column = 8 Or _
    Target.Column = 9 Then[/COLOR][/SIZE][/FONT]
 
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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