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

Repeat Last Command
Pressing F4 adds dollar signs when editing a formula. When not editing, F4 repeats last command.
Try this,
Code:
[FONT="Consolas"][SIZE="2"][COLOR="Navy"]Option Explicit

Private Sub WorkSheet_Change(ByVal Target As Range)

    Dim oldval As String
    Dim newval As String

    If Target.Count > 1 Then Exit Sub
    If Target.Column = 7 Then
        newval = Target.Value
        If newval <> "" Then
            Application.EnableEvents = False
            Application.Undo
            oldval = Target.Value
            If InStr(oldval, newval) = 0 Then
                Target.Value = IIf(oldval = "", "", oldval & ",") & newval
            End If
            Application.EnableEvents = True
        End If
    End If

End Sub[/COLOR][/SIZE][/FONT]
 
Upvote 0
code which you given is not working if am closing and then opening the file... pls make it as working at all the time:(
 
Upvote 0
The code is a worksheet event. It has nothing to do with opening and closing a workbook.

What are you getting exactly?

I've tried it on my copy and, as expected, not affected by opening and closing a workbook.
 
Upvote 0
just used this code in my new Excel and applied the code to dropdown, it has woreked fine. but it is not working if am closing the file and opening to re-use it.

pblm is - code not working if i re-opening to use the file once closed, it is not allowing me to select multiple options from dropdown... just i could select only 1 from the list as usual...
 
Upvote 0
This is weird!

I can think of one thing, what is your Excel version?

If it is 2007 or 2010, then what is the file extension?
 
Upvote 0
I was thinking that macros are not enabled. When you copied the code it works but when saving the workbook and load it again the code will not run.

Did you check this?

Do you have other code in the workbook that runs normally?
 
Upvote 0
yes i have other code in my workbook which will run along with it...

macro is in enabled mode only
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,917
Members
452,366
Latest member
TePunaBloke

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