VBA: How to lock cells after data entry

lennarp

New Member
Joined
Jan 17, 2013
Messages
2
Hi All,

I am having some trouble with achieving my desired outcome in Excel.

I am setting up a spreadsheet that gives the ability of the user to enter timmings for specific activities. I am using a timestamp whereby the user can click on column 2 & column 6
which is the 'Start' & 'End' time. In column 7 would give the total time it took to complete that activity/phone call (= column 6 - column 2).

Here is my initial code which appears to work well and gives the time down to the second.


Private Sub Worksheet_SelectionChange(ByVal Target As Range)</SPAN></SPAN>
If Target.Columns.Count > 1 Then Exit Sub</SPAN></SPAN>
If Target.Column <> 6 And Target.Column <> 2 Then Exit Sub</SPAN></SPAN>
Target.Value = Now - Date</SPAN></SPAN>
Target.NumberFormat = "h:m:ss"</SPAN></SPAN>

End Sub


However I need to ensure that when users enter data into both these columns the cells automatically lock to ensure they dont overwrite the data. Furthermore if the user clicks on the entire Column by selecting 'column B' for instances it automatically populates the data in every single cell from B1-B1000000 ETC.


1. How can I look the cells so it does not overwrite previous data
2. Ensure that if users click on the entire column it wont pre populate thounds of cells of data.


Any help would be appreciated.

Cheers
</SPAN></SPAN>
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
This won't overwrite a time stamp if they select a previously populated cell, but it doesn't "lock" the data either. Is that what you want?

Rich (BB code):
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Count > 1 Then Exit Sub
    If Target.Column <> 6 And Target.Column <> 2 Then Exit Sub
    If Target.Value <> "" Then Exit Sub
    Target.Value = Time
    Target.NumberFormat = "h:m:ss"
End Sub
 
Last edited by a moderator:
Upvote 0

Forum statistics

Threads
1,213,551
Messages
6,114,272
Members
448,558
Latest member
aivin

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