VBA - Restriction of Copy/Paste on dropdown list not working when the file is shared

Clemmye

New Member
Joined
Dec 16, 2016
Messages
1
Hello,

Here's my first post and question.
So I've got an issue with a part of my VBA code when I share my file (the file needs to be shared unfortunately).
The trouble that I've got is that I use multiple DataValidation lists, and as I saw that some people were pasting their own data onto it (didn't find the origin yet), I tried to protect it (code below).
Also, in this code, there's a protectiong to restict edition on cells with formulas, and that part works fine when the file is in Shared mode.

However, the protection onto dropdown lists isn't working. I tested to see what was going off, and basically, the file considers that the data entered is valid when the file is shared (and also when I unshare it right before the vba does the event...)

I have no idea on how I could make this thing work :

Code:
Private Sub Worksheet_Change(ByVal Target As Range)
    
    'Does the validation range still have validation?
   If Not HasValidation(Range("ValidationRange1, ValidationRange2, ValidationRange3, ValidationRange4, ValidationRange5, ValidationRange6, ValidationRange7, ValidationRange8, ValidationRange9, ValidationRange10, ValidationRange11")) Or Not Intersect(Range("G5:G900,I5:I900,O5:O900,R5:R900"), Target) Is Nothing Then
        Application.EnableEvents = False
        Application.Undo
        Application.EnableEvents = True
        MsgBox "Impossible de coller des données dans cette cellule." & Chr(10) & _
        "Un menu déroulant est disponible." & Chr(10) & _
        "En cas de problème : xxxx.", vbCritical
    End If
    
End Sub

Function HasValidation(R) As Boolean
'  Returns True if every cell in Range r uses Data Validation
   On Error Resume Next
    HasValidation = True
    If R.Areas.Count > 1 Then
      For Each ar In R.Areas
          x = ar.Validation.Type
          If Err.Number <> 0 Then HasValidation = False
      Next
    Else
      x = R.Validation.Type
      If Err.Number = 0 Then HasValidation = True Else HasValidation = False
    End If
End Function

Thanks for all the help you could provide to me.

PS: I've tried to write the dropdowns lists on VBA... same trouble
 

Excel Facts

Is there a shortcut key for strikethrough?
Ctrl+S is used for Save. Ctrl+5 is used for Strikethrough. Why Ctrl+5? When you use hashmarks to count |||| is 4, strike through to mean 5.

Forum statistics

Threads
1,223,909
Messages
6,175,313
Members
452,634
Latest member
cpostell

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