A Microsoft Office (Excel, Word) forum. OfficeFrustration

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » OfficeFrustration forum » Microsoft Excel » Worksheet Functions
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Lock after entering



 
 
Thread Tools Display Modes
  #1  
Old August 3rd, 2008, 05:11 AM posted to microsoft.public.excel.worksheet.functions
bgkgmg
external usenet poster
 
Posts: 19
Default Lock after entering

Cell B2 has the formula SUM(A1,A3). After entering data in A1 and A3 the sum
appears in B2. I would like to lock only B2 after data entry so it never
changes. Is it possible?

Thanks
  #2  
Old August 3rd, 2008, 03:41 PM posted to microsoft.public.excel.worksheet.functions
Gary''s Student
external usenet poster
 
Posts: 7,584
Default Lock after entering

Start with all cells ujnlocked and the sheet unprotected.

The following worksheet event macro will monitor A1 and A3. Once they are
both filled in, the formula in B2 will be converted to a value and B2 will be
locked:

Private Sub Worksheet_Calculate()
Set a1 = Range("A1")
Set a3 = Range("A3")
Set b2 = Range("B2")
If IsEmpty(a1.Value) Then Exit Sub
If IsEmpty(a3.Value) Then Exit Sub
If Not b2.HasFormula Then Exit Sub
b2.Value = b2.Value
b2.Locked = True
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True
End Sub


Because it is worksheet code, it is very easy to install and automatic to use:

1. right-click the tab name near the bottom of the Excel window
2. select View Code - this brings up a VBE window
3. paste the stuff in and close the VBE window

If you have any concerns, first try it on a trial worksheet.

If you save the workbook, the macro will be saved with it.


To remove the macro:

1. bring up the VBE windows as above
2. clear the code out
3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm

--
Gary''s Student - gsnu200797


"bgkgmg" wrote:

Cell B2 has the formula SUM(A1,A3). After entering data in A1 and A3 the sum
appears in B2. I would like to lock only B2 after data entry so it never
changes. Is it possible?

Thanks

 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT +1. The time now is 08:01 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.