Protect or clear VBA command also locking cells (1 Viewer)

laxster

Registered User.
Local time
Today, 17:19
Joined
Aug 25, 2009
Messages
145
Hi,

I'm having an issue with a particular bit of code. All the cells are unlocked prior to running the code. After I run the code, the cells also get locked up, which is not desired. I'm bashing my head trying to figure out why these cells are getting locked up, as nowhere do I have any command or code telling these cells to lock up. I've messed with the range, and it seems that when I modify the range, it'll lock the cells up to that point, and no further. ( Range("C9:K65536").Cells.Clear line of code )

Here is my code:

Code:
Sub DeleteEntryData()
    Dim iRet As Integer
    Dim strPrompt As String
    Dim strTitle As String
 
    ' Promt
    strPrompt = "Do you wish to delete the Entry tab data?  This cannot be undone."
 
    ' Dialog's Title
    strTitle = "Warning: Data Deletion"
 
    'Display MessageBox
    iRet = MsgBox(strPrompt, vbYesNo, strTitle)
 
    ' Check pressed button
    If iRet = vbNo Then
        MsgBox "Data will not be removed."
    Else
        MsgBox "Your entry data will be deleted.  If this was accidental, please close the file without saving changes."
'Copies days since last empty
Sheets("Journal").Unprotect Password:="trend sheet"
Sheets("Journal").Select
Range("T5:T105").Copy
Range("U5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Sheets("Journal").Protect Password:="trend sheet"
Range("A1").Select
 
'Deletes entry data
Sheets("Entry").Select
Sheets("Entry").Unprotect Password:="trend sheet"
Range("C9:K65536").Cells.Clear
Sheets("Entry").Protect Password:="trend sheet"
Range("A1").Select
 
    End If
End Sub

Could someone guide me in the right direction?
 

Ziggy1

Registered User.
Local time
Today, 23:19
Joined
Feb 6, 2002
Messages
462
Hi,

Here is my code:

Code:
Sub DeleteEntryData()
    Dim iRet As Integer
    Dim strPrompt As String
    Dim strTitle As String
 
    ' Promt
    strPrompt = "Do you wish to delete the Entry tab data?  This cannot be undone."
 
    ' Dialog's Title
    strTitle = "Warning: Data Deletion"
 
    'Display MessageBox
    iRet = MsgBox(strPrompt, vbYesNo, strTitle)
 
    ' Check pressed button
    If iRet = vbNo Then
        MsgBox "Data will not be removed."
    Else
        MsgBox "Your entry data will be deleted.  If this was accidental, please close the file without saving changes."
'Copies days since last empty
Sheets("Journal").Unprotect Password:="trend sheet"
Sheets("Journal").Select
Range("T5:T105").Copy
Range("U5").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
Sheets("Journal").Protect Password:="trend sheet"
Range("A1").Select
 
'Deletes entry data
Sheets("Entry").Select
Sheets("Entry").Unprotect Password:="trend sheet"
Range("C9:K65536").Cells.Clear
[B][COLOR="Red"]Sheets("Entry").Protect Password:="trend sheet"[/COLOR][/B]
Range("A1").Select
 
    End If
End Sub

Could someone guide me in the right direction?



see the bolded entry above..
 

Users who are viewing this thread

Top Bottom