Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Junior Member
 
Posts: 4
Default Protection not allowing Validation

Hi,

I have a small piece of VBA which adds custom data validation on certain cells in my worksheet. These cells are not locked or hidden but when I protect the worksheet, this code does not work.

There does not appear to be any options to allow this code to work when I protect the sheet and I do not have a password on it.

Has anyone encountered this before? Could someone point me in the right direction?

Many thanks
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Protection not allowing Validation

cosmmarchy expressed precisely :
Hi,

I have a small piece of VBA which adds custom data validation on certain
cells in my worksheet. These cells are not locked or hidden but when I
protect the worksheet, this code does not work.

There does not appear to be any options to allow this code to work when
I protect the sheet and I do not have a password on it.

Has anyone encountered this before? Could someone point me in the right
direction?

Many thanks


Typically, code will not work on protected sheets unless the protection
parameter 'UserInterfaceOnly' is set 'True'! Unfortunately, this is a
non-persistent setting meaning it will not have effect next time the
file is opened unless you reset protect when it opens. Resetting
protection requires existing protection be removed, then re-applied.

You can accomplish this via the Workbook_Open() event behind the
'ThisWorkbook' object, OR by using an Auto_Open() procedure in a
standard module. I prefer the latter but this is just my preference
because there are issues with using Workbook_Open() or
Workbook_BeforeClose() if your file becomes corrupt.

Here's some sample code I typically use in a standard module named
"_mOpenClose", which I use in all my VBA projects...


Option Explicit
Const PWRD As String = "password"

Sub Auto_Open()
StoreExcelSettings: MakeMenus: SetupUI: ProtectAllSheets
End Sub 'Auto_Open

Sub Auto_Close()
RemoveMenus: RestoreExcelSettings: RestoreUI
End Sub 'Auto_Close


Sub ProtectAllSheets(Optional Wkb As Workbook)
Dim wks As Worksheet
If Wkb Is Nothing Then Set Wkb = ActiveWorkbook
For Each wks In Wkb.Worksheets: ResetProtection wks: Next 'wks
End Sub 'ProtectAllSheets

Sub ResetProtection(Optional Wks As Worksheet)
If Wks Is Nothing Then Set Wks = ActiveSheet
Wks.Unprotect PWRD: wksProtect Wks
End Sub 'ResetProtection

Sub wksProtect(Optional Wks As Worksheet)
' Protects specified sheets according to Excel version.
' Assumes Public Const PWRD as String contains the password, even if
there isn't one.
'
' Arguments: Wks [In] Optional. Ref to the sheet to be protected.
' (Defaults to ActiveSheet if missing)

If Wks Is Nothing Then Set Wks = ActiveSheet
On Error Resume Next
With Wks
If Val(Application.VERSION) = 10 Then
'Copy/paste the desired parameters above the commented line.
.Protect Password:=PWRD, _
DrawingObjects:=False, Contents:=True, Scenarios:=True, _
UserInterfaceOnly:=True, _
AllowFiltering:=True, _
AllowFormattingColumns:=True, _
AllowFormattingRows:=True, _
AllowFormattingCells:=True ', _
AllowDeletingColumns:=True, _
AllowDeletingRows:=True, _
AllowInsertingColumns:=True, _
AllowInsertingHyperlinks:=True, _
AllowInsertingRows:=True, _
AllowUsingPivotTables:=True
Else
.Protect Password:=PWRD, _
DrawingObjects:=False, Contents:=True, Scenarios:=True,
UserInterfaceOnly:=True
End If
' .EnableAutoFilter = True
' .EnableOutlining = True

' .EnableSelection = xlNoRestrictions
.EnableSelection = xlUnlockedCells
' .EnableSelection = xlNoSelection
End With
End Sub

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 31
Default Protection not allowing Validation

Please post the smallest sample that does not work.

Robert Flanagan
Add-ins.com LLC
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel


On Thursday, June 14, 2012 5:55:46 AM UTC-4, cosmmarchy wrote:
Hi,

I have a small piece of VBA which adds custom data validation on certain
cells in my worksheet. These cells are not locked or hidden but when I
protect the worksheet, this code does not work.

There does not appear to be any options to allow this code to work when
I protect the sheet and I do not have a password on it.

Has anyone encountered this before? Could someone point me in the right
direction?

Many thanks




--
cosmmarchy

  #4   Report Post  
Junior Member
 
Posts: 4
Default

Hi, attached is a stripped down example.

What should happen is when you click on the bordered column B cells the data validation is set up for that cell and the column C cell validation should be setup when that is clicked.

What actually happens is with the protection enabled, any previously clicked cell will retain any validation but a newly clicked cell will not be able to have any validation setup because it is locked.

The protection code is of that above so the password is 'password'!!

Thanks

Quote:
Originally Posted by Bob Flanagan[_4_] View Post
Please post the smallest sample that does not work.

Robert Flanagan
Add-ins.com LLC
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel


On Thursday, June 14, 2012 5:55:46 AM UTC-4, cosmmarchy wrote:
Hi,

I have a small piece of VBA which adds custom data validation on certain
cells in my worksheet. These cells are not locked or hidden but when I
protect the worksheet, this code does not work.

There does not appear to be any options to allow this code to work when
I protect the sheet and I do not have a password on it.

Has anyone encountered this before? Could someone point me in the right
direction?

Many thanks




--
cosmmarchy
Attached Files
File Type: zip Example.zip (25.6 KB, 37 views)
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default Protection not allowing Validation

Sounds to me like you want 'conditional' validation in colC based on
selection in colB. Have a look at...

http://www.contextures.com/xlDataVal02.html

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup!
comp.lang.basic.visual.misc
microsoft.public.vb.general.discussion


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Data Validation - allowing only negative numbers or converting Courtney Excel Discussion (Misc queries) 14 April 24th 23 09:01 AM
Protection not allowing Validation cosmmarchy Excel Programming 0 June 14th 12 10:54 AM
Data Validation Lists - Allowing no other entries KKD Excel Discussion (Misc queries) 0 June 5th 09 09:33 PM
Data Validation - Only Allowing certain characters Marcus Excel Worksheet Functions 1 May 28th 07 01:34 PM
using protection (but allowing a combobox to still work) neowok[_39_] Excel Programming 5 March 4th 04 02:48 PM


All times are GMT +1. The time now is 10:06 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"