close

i´m developing a excel file that will be filled while whatching a soccer
game. Sometimes, lots of data must be inserted in small colums/rows in just a
few seconds, and i dont want to overwrite data that i had inserted before by
mistake. I´d like that excel blocks a cell that was modified (data was
inserted). With quot;block cellquot; i mean that if I click that cell again i wont be
able to modify the information that i had inserted before. Is that possible?
I really dont know much about macros (just learned), so please teach it for a
new user!

Say you wanted to restrict this to Sheet 1 Range A1:C20, then the
following code placed into the Sheet1 code module will protect a cell
if it is in that range and you have just entered into it a new value.
If you really need to change that cells value you would have to remove
the sheet protection first.
Before the code will work as expected you will have to unlock all the
cells on that sheet. Select the entire sheet by clicking on the grey
space above row 1's row number and just left of column A's column
label, then go Formatgt;Cellsgt;Protectiongt; de-select Locked.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column gt; 3 Or Target.Row gt; 20 Then
Exit Sub
End If
Me.Unprotect
Target.Locked = True
Me.Protect
End Sub

To get the code into place..

1. Copy it
2. Right click the Sheet's sheet tab then select quot;View Codequot; from the
popup.
3. Paste the code
4. Return to the worksheet by either Alt F11 or going Filegt;quot;Close and
return to Microsoft Excelquot;

If you use this method your Security level will have to be Medium.
Toolsgt;Macrogt;Securitygt;Medium. Also, everytime you open the workbook you
must click quot;Enable Macrosquot; on the quot;Security Warningquot; dialog

Ken JohnsonThanks a lot ken! that was perfect. This forum is very usefull..
quot;Ken Johnsonquot; escreveu:

gt; Say you wanted to restrict this to Sheet 1 Range A1:C20, then the
gt; following code placed into the Sheet1 code module will protect a cell
gt; if it is in that range and you have just entered into it a new value.
gt; If you really need to change that cells value you would have to remove
gt; the sheet protection first.
gt; Before the code will work as expected you will have to unlock all the
gt; cells on that sheet. Select the entire sheet by clicking on the grey
gt; space above row 1's row number and just left of column A's column
gt; label, then go Formatgt;Cellsgt;Protectiongt; de-select Locked.
gt;
gt; Private Sub Worksheet_Change(ByVal Target As Range)
gt; If Target.Column gt; 3 Or Target.Row gt; 20 Then
gt; Exit Sub
gt; End If
gt; Me.Unprotect
gt; Target.Locked = True
gt; Me.Protect
gt; End Sub
gt;
gt; To get the code into place..
gt;
gt; 1. Copy it
gt; 2. Right click the Sheet's sheet tab then select quot;View Codequot; from the
gt; popup.
gt; 3. Paste the code
gt; 4. Return to the worksheet by either Alt F11 or going Filegt;quot;Close and
gt; return to Microsoft Excelquot;
gt;
gt; If you use this method your Security level will have to be Medium.
gt; Toolsgt;Macrogt;Securitygt;Medium. Also, everytime you open the workbook you
gt; must click quot;Enable Macrosquot; on the quot;Security Warningquot; dialog
gt;
gt; Ken Johnson
gt;
gt;

Hi Fecozisk,

You're welcome.
Thanks for the feedback.

Ken Johnson

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 software 的頭像
    software

    software

    software 發表在 痞客邦 留言(0) 人氣()