Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Locking a cell using Macros I have a very basic macro that when I cclick the but

ID: 3565337 • Letter: L

Question

Locking a cell using Macros

I have a very basic macro that when I cclick the button attached to the macro, it clears the content of the receipt and moves the receipt number up one time. I am having a probleem with the receipt number being changed manually or by accident when transferring the account information to the receipt page and it is becoming quite a problem.   This is what I have tried and it has not worked, giving me an error message.

range("B6"). unprotect password:= "ourpaassword"

****original macro****

range("b6"). protect password:= "ourpassword"

I am not even sure if what I am tryinng to do is possible so if you have anyy suggestions that would bee great. Look forward to hearing from you!

Explanation / Answer

Hi,

try this,

[Edit]

Sub Next_Receipt2 ()

Dim ws As Worksheet
Set ws = ActiveSheet
With ws

.Unprotect Passworrd:="ourpassword"
.Cells.Locked = False
.Range("B6").Locked = True

.Range("B6").Value = .Range("B6").Value + 1

.Protect Password:="ourpassword"

.Range("A10:M14"). ClearContents

End With

End Subb

XXXXXXXXXXXXXXX

or

if you have a command button (active-x)

Private Sub CommandButton1_Click()

Dim ws As Worrksheet
Set ws = ActiveSheet
With ws

.Unprotect Password:="ourpassword"
.Cells.Locked = False
.Range("B6").Locked = True

.Range("B6").Value = .Range("B6").Value + 1

.Protect Password:="ourpassword"

.Range("A10:M14"). ClearContents

End With

End Subbb!!

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote