Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Microsoft Office > Excel VBA > Excel VBA
|
Excel VBA Discuss using VBA for Excel programming.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Excel VBA section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 23rd, 2010, 04:49 PM
Registered User
 
Join Date: Apr 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Probably a common question. Any help?

I am kind of new at writing macros into Excel and I have come across a doozy that I'm hoping someone can help me with.

I want to create a sheet that employees can enter data into and when they get to the end of the row and enter their initials, the date and time are automatically entered. That part I can do. However, I do not want the employees to be able to delete the time/date stamp. I lock the cells so that they cannot be edited, but, of course, I have an error come up because the macro is trying to put data into the cell and the cell is locked from data entry. What I need is a macro that will unlock the cells, write the time and date and then relock the cells. I have heard that such a beast exists, but I have not seen it and do not know the appropriate code myself.

Anybody able to help?

Thanks in advance,

Michael
 
Old April 23rd, 2010, 09:17 PM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

Hi

Can you check if the following code might help:

Code:
Sub Unprotect_And_ThenProtect()
    
    ActiveSheet.Unprotect
    Range("A2").Value = Now()
    ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub
Cheers
Shasur
__________________
C# Code Snippets (http://www.dotnetdud.blogspot.com)

VBA Tips & Tricks (http://www.vbadud.blogspot.com)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Profile common bendjoe BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 13 October 12th, 2010 02:26 AM
Common value scandalous Excel VBA 1 December 21st, 2007 11:01 PM
common code austinf XSLT 3 May 3rd, 2006 09:38 AM
what is the common approach for it? thanks Robin1 Classic ASP Databases 6 September 11th, 2004 04:14 AM
Common question, not so common answer? flyin ADO.NET 5 March 24th, 2004 06:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.