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 :
Thanks for all the help you could provide to me.
PS: I've tried to write the dropdowns lists on VBA... same trouble
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