Consulting

Results 1 to 7 of 7

Thread: Solved: Strange problem when protecting/unprotecting sheets

  1. #1

    Solved: Strange problem when protecting/unprotecting sheets

    I'm working on a difficult workbook since I never know how many rows there will be. Since the users only should enter data in Sheet1 and on Sheet 2-4 only be able to fill in data in one cell, like E13. I protected the sheet except the cell where the user is able to enter data, which then calculates some money to dispense.

    I copy the data to the other sheets when the user leaves the G column. No problems there.

    I have this code.
    [VBA]Sub Skydda_Blad()
    Dim wrbBok As Workbook
    Dim wrsAktivtBlad As Worksheet, wsBlad As Worksheet

    Set wrbBok = ActiveWorkbook
    Set wrsAktivtBlad = ActiveSheet
    'Loop through all sheets
    For Each wsBlad In Worksheets

    'Sheet that we wont protect
    If wsBlad.Name = "Sheet1" Then GoTo NastaBlad
    If wsBlad.Name <> wrsAktivtBlad.Name Then
    wsBlad.Protect Password:="a1b2c3d4" ' not the actual password ;-)
    End If

    NastaBlad:
    Next wsBlad

    End Sub[/VBA]

    This gives me a strange behavior that I get cells selected and then cant work, Excel won't let me change cell with tab or enter. Does anyone have a better code or any idea why excel behaves like this?

    What I want is that the data from Sheet1 is copied to Sheet2-4 but the user should only be getting access to one cell.

    Ask if it's unclear what I mean and I'll try to explain.
    The use of this workbook is so complicated that I have problem explaining it even in my native language.

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Do you have the locked property of E13 set to disabled?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    I locked every cell except E13. As I understand it, locking cells and protect the sheet is one way to prevent users from accessing the cells accept the ones allowed. Since I copy data from Sheet1 to the other three I need to unprotect the sheet and then protect them again, this gives me the strange behavior.

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    You are absolutely right, and what you are doing should work fine, so I am a bit mystified. Can you post the workbook?
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  5. #5
    Knowledge Base Approver VBAX Wizard p45cal's Avatar
    Joined
    Oct 2005
    Location
    Surrey UK
    Posts
    5,876
    Quote Originally Posted by Cougarina
    Since I copy data from Sheet1 to the other three I need to unprotect the sheet and then protect them again
    Not to manipulate data with vba you don't!
    If you use the likes of:
    wsBlad.Protect userinterfaceonly:=true
    this will allow vba to move things around, but not the user.
    However, this command only remains active for that session (while the workbook is open). If the workbook is closed, then reopened, you have to execute the statement again. So put a statement for each sheet that needs to have it, in the Workbook_Open event.
    p45cal
    Everyone: If I've helped and you can't be bothered to acknowledge it, I can't be bothered to look at further posts from you.

  6. #6
    Thanks to both of you for helping. Will try p45Cal's example as I think it will help me solve the problem.

  7. #7
    I cant seems to get it working. I get a message telling me that the sheet is protected. So back to square one then with the protect/unprotect mess.

    [Edit] Got it working now. Sheet2.Protect Password:="1a2b3c4d", UserInterFaceOnly:=True, now I can continue to make the rest work.
    on me.
    [/edit]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •