Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default lock cells after entry

Hi, I'm currently making a program using excel. Currently, I've been able to
transfer data from userform to excel after clicking the submit button. Now, I
wanted to protect each entry by locking them after entry. Basically, I have 6
fields: Date, Name, Comments, Amount 1, Amount 2, Total Amount
The sixth field being a formula meant that it didn't need to be added to the
form.

The way I wanted it to be:
1. Fill up form
2. Submit
3. Form transfers data to worksheet
4. Form locks worksheet but available for viewing

I've already set the worksheet protection to not be able to do anything
besides viewing.

Here's my current "uncompleted" code which I hope is do-able.

Private Sub CommandButton1_Click()
Dim LastRow As Object


Set LastRow = Sheet1.Range("a65536").End(xlUp)
ThisWorkbook.Unprotect Password = "pwd"
LastRow.Offset(1, 0).Value = Now
LastRow.Locked = True
LastRow.Offset(1, 1).Value = TextBox1.Text
LastRow.Locked = True
LastRow.Offset(1, 2).Value = TextBox4.Text
LastRow.Locked = True
LastRow.Offset(1, 3).Value = TextBox2.Text
LastRow.Locked = True
LastRow.Offset(1, 4).Value = TextBox3.Text
LastRow.Locked = True
ThisWorkbook.Protect Password = "pwd"

MsgBox "Entry Added!"

response = MsgBox("New Entry?", _
vbYesNo)

If response = vbYes Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox1.SetFocus

Else
Unload Me
End If

End Sub

Any suggestions or fixes for this would be greatly appreciated.

--
Message posted via http://www.officekb.com

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default lock cells after entry

Nvm. Did a little more experimenting and found the solution:

1. Changed [ThisWorkbook.Unprotect Password = "pwd"] to [Sheet1.Unprotect
Password = "pwd"]
2. Changed [LastRow.Locked = True] to [LastRow.Offset(1, X).Locked = True]
3. Changed [ThisWorkbook.Protect Password = "pwd"] to [Sheet1.Protect
Password = "pwd"]
4. Removed other sheets.

maximillan wrote:
Hi, I'm currently making a program using excel. Currently, I've been able to
transfer data from userform to excel after clicking the submit button. Now, I
wanted to protect each entry by locking them after entry. Basically, I have 6
fields: Date, Name, Comments, Amount 1, Amount 2, Total Amount
The sixth field being a formula meant that it didn't need to be added to the
form.

The way I wanted it to be:
1. Fill up form
2. Submit
3. Form transfers data to worksheet
4. Form locks worksheet but available for viewing

I've already set the worksheet protection to not be able to do anything
besides viewing.

Here's my current "uncompleted" code which I hope is do-able.

Private Sub CommandButton1_Click()
Dim LastRow As Object


Set LastRow = Sheet1.Range("a65536").End(xlUp)
ThisWorkbook.Unprotect Password = "pwd"
LastRow.Offset(1, 0).Value = Now
LastRow.Locked = True
LastRow.Offset(1, 1).Value = TextBox1.Text
LastRow.Locked = True
LastRow.Offset(1, 2).Value = TextBox4.Text
LastRow.Locked = True
LastRow.Offset(1, 3).Value = TextBox2.Text
LastRow.Locked = True
LastRow.Offset(1, 4).Value = TextBox3.Text
LastRow.Locked = True
ThisWorkbook.Protect Password = "pwd"

MsgBox "Entry Added!"

response = MsgBox("New Entry?", _
vbYesNo)

If response = vbYes Then
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox1.SetFocus

Else
Unload Me
End If

End Sub

Any suggestions or fixes for this would be greatly appreciated.


--
Message posted via OfficeKB.com
http://www.officekb.com/Uwe/Forums.a...mming/200704/1

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can I lock a cell after data entry so entry can not be changed Verlinde Excel Discussion (Misc queries) 3 April 22nd 10 07:59 PM
Lock out data entry in a cell DShaver Excel Discussion (Misc queries) 1 August 27th 09 07:29 PM
Lock Row after Data Entry boatnisfun Excel Discussion (Misc queries) 1 March 10th 07 08:03 AM
Lock cell entry Sprankler Excel Worksheet Functions 1 November 17th 05 03:50 PM
After Entry - Lock and Go to Certain Cell Paige Excel Programming 0 August 3rd 05 09:56 PM


All times are GMT +1. The time now is 02:15 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"