+ Reply to Thread
Results 1 to 12 of 12

VBA Clearing Data from Visible Cells Only & Copying Worksheet with Protection in Place

Hybrid View

  1. #1
    Registered User
    Join Date
    04-13-2017
    Location
    Birmingham
    MS-Off Ver
    2016
    Posts
    31

    VBA Clearing Data from Visible Cells Only & Copying Worksheet with Protection in Place

    Me again, a few question on cell protection.

    I am only looking to protect certain cells, which I can do, but I encounter a few issues that may or may not be resolvable.

    1. I hide the cells I have protected. I would like to be able to select all visible cells in one go, press delete and have the data removed. At the moment it wont let me do that as when you select all the visible cells in one move of the mouse it catches all the hidden cells as well. Is there a way to clear all the unlocked cells of data? I dont want the whole sheet to be wiped though, just the times (see attached file).

    2. I have a blank template that I intend for people to just cut and paste in to a new worksheet each time they need to create a new rota. This way it keeps comment notes and names in the right order etc. When I do this the protection vanishes.
    Attached Files Attached Files
    Last edited by AliGW; 11-04-2018 at 07:13 AM.

  2. #2
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Cell protection problems

    You could delete all those columns:

    A
    B
    C
    D
    E
    F
    G
    H
    I
    J
    K
    L
    M
    N
    O
    P
    Q
    4
    In
    Out
    In
    Out
    In
    Out
    In
    Out
    In
    Out
    In
    Out
    In
    Out
    5
    Billy
    10:00
    18:00
    10:00
    18:00
    10:00
    23:30
    10:00
    23:30
    10:00
    20:00
    53:00
    P5: =SUMIF($B$4:$O$4, "Out", B5:O5) - SUMIF($B$4:$O$4, "In", B5:O5)
    Entia non sunt multiplicanda sine necessitate

  3. #3
    Registered User
    Join Date
    04-13-2017
    Location
    Birmingham
    MS-Off Ver
    2016
    Posts
    31

    Re: Cell protection problems

    I am using all those cells as they transfer across to another sheet which works out wages.
    I could make a more complicated sheet I suppose where totals are worked out only on the wages sheet.

  4. #4
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678

    Re: Cell protection problems

    In general, IMO, it's a mistake to intersperse data entry cells and calculation cells. It doesn't need to be more complicated, just more thoughtfully arranged.

  5. #5
    Registered User
    Join Date
    04-13-2017
    Location
    Birmingham
    MS-Off Ver
    2016
    Posts
    31

    Re: Cell protection problems

    Indeed, and your suggestion lead me to taking all those sells out and shifting them all to one side. They can all be hidden now and I can delete the data in all the other cells without deleting the formulas.

    The rest of the cells I dont want changed should easily be locked out now as they dont need to be hidden.

    Thanks

    ANy thoughts on the issue of cutting and pasting a master sheet to a new sheet and having the protections stay in place?

  6. #6
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Perth Western Australia
    MS-Off Ver
    Office 365
    Posts
    257

    Re: Cell protection problems

    Hi

    Have you thought having the cut and paste being done by vba with a button for users that sets up a input spreadsheet for users? This would retain the master.
    How do you propose data to transfer from users to the final master and subsequently the payroll input?

    It would be wise to have a master template that is not used at all for backup.

    Cheers

  7. #7
    Registered User
    Join Date
    04-13-2017
    Location
    Birmingham
    MS-Off Ver
    2016
    Posts
    31

    Re: Cell protection problems

    Unless the spreadsheet could be printed out in the layout in the file it wouldnt be any use.

    The user (9 times out of 10 its me, but occasionally someone else) will enter the data on the rota, another workbook with then reference the hours for each employee each day and do its calculations to produce how much money they are owed and how much holiday they have accrued. The only manual input on that sheet should be how many hours holiday an employee might have taken.

    There are some fiddly bits that you will have to do manually though, such as cut off dates for pay roll, and changing sheet locations in formulas. I have no clue where to start in making that automatic - probably not possible, but dont mind spending a day setting up the workbooks for an entire year.

    I'm reasonably happy where I am at at the moment, afew issues like holiday pay and split shifts to think through but overall i'd like to make it as simple to use as possible. Cell protection is one such measure I would like to use at some point.

  8. #8
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,631

    Re: Cell protection problems

    I am not a VBA expert, but it seems to me that two VBA routines would help you here. Shall I move you to the VBA section?
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  9. #9
    Registered User
    Join Date
    04-13-2017
    Location
    Birmingham
    MS-Off Ver
    2016
    Posts
    31

    Re: Cell protection problems

    YOu can but I have no clue what VBA. If it will help me I will take a look. Thanks

  10. #10
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,631

    Re: Cell protection problems

    It's Visual Basic for Applications - it's the language used in macros.

  11. #11
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2406 (Windows 11 23H2 64-bit)
    Posts
    81,631

    Re: VBA Clearing Data from Visible Cells Only & Copying Worksheet with Protection in Place

    Thread moved and title updated for clarity.

  12. #12
    Forum Contributor
    Join Date
    01-09-2016
    Location
    Perth Western Australia
    MS-Off Ver
    Office 365
    Posts
    257

    Re: VBA Clearing Data from Visible Cells Only & Copying Worksheet with Protection in Place

    Hi

    Excel VBA is a tool available to automate repetitive tasks such as deleting multiple columns of data leaving protected cells alone.

    In this instance I think I have achieved your aim. Deleting unprotected cells through recording a macro to do the task. I have added a button so that using this spreadsheet or a copy of it you can run the job whenever you want. What I have done is crude but it works. A more sophisticated approach can deliver more.

    Withhout being critical because I firmly promote learning being self taught therefore probably not as good as some but as good as a lot, read any introduction to Excel to point you in a direction. Macro are not the b all and end all but can help.

    I have attached a revised spreadsheet with the code below if you are interested.
    ub Macro1()
    '
    ' Macro1 Macro
    '
    
    '
        Range("B5:C32").Select
        Selection.ClearContents
        ActiveWindow.SmallScroll Down:=21
        Range("B34:C39").Select
        Selection.ClearContents
        Selection.ClearContents
        Range("B41:C42").Select
        Selection.ClearContents
        ActiveWindow.SmallScroll Down:=-42
        Range("E5:F32").Select
        Selection.ClearContents
        ActiveWindow.SmallScroll Down:=28
        Range("E34:F39").Select
        Selection.ClearContents
        Range("E41:F42").Select
        Selection.ClearContents
        ActiveWindow.SmallScroll Down:=-42
        Range("H5:I32").Select
        Selection.ClearContents
        ActiveWindow.SmallScroll Down:=21
        Range("H34:I39").Select
        Selection.ClearContents
        Range("H41:I42").Select
        Selection.ClearContents
        ActiveWindow.SmallScroll Down:=-35
        Range("K5:L32").Select
        Selection.ClearContents
        ActiveWindow.SmallScroll Down:=21
        Range("K34:L39").Select
        Selection.ClearContents
        Range("K41:L42").Select
        Selection.ClearContents
        ActiveWindow.SmallScroll Down:=-28
        Range("N5:O32").Select
        Selection.ClearContents
        ActiveWindow.SmallScroll Down:=21
        Range("N34:O39").Select
        Selection.ClearContents
        Range("N41:O42").Select
        Selection.ClearContents
        ActiveWindow.SmallScroll Down:=-35
        Range("Q5:R32").Select
        Selection.ClearContents
        ActiveWindow.SmallScroll Down:=14
        Range("Q34:R39").Select
        Selection.ClearContents
        Range("Q41:R42").Select
        Selection.ClearContents
        ActiveWindow.SmallScroll ToRight:=5
        ActiveWindow.SmallScroll Down:=-28
        Range("T5:U32").Select
        Selection.ClearContents
        ActiveWindow.SmallScroll Down:=14
        Range("T34:U39").Select
        Selection.ClearContents
        Range("T41:U42").Select
        Selection.ClearContents
        ActiveWindow.SmallScroll Down:=-35
        Range("AA15").Select
        ActiveCell.FormulaR1C1 = "Finished"
        Range("AA17").Select
    End Sub
    PS it took longer to write the reply than record the macro. Please respond if this helps and hopefully I can provide some further assistance

    Cheers
    Attached Files Attached Files

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. [SOLVED] Cell protection
    By filipa in forum Excel General
    Replies: 4
    Last Post: 08-27-2017, 11:03 AM
  2. Protection problems
    By tornqvis in forum Excel General
    Replies: 2
    Last Post: 04-16-2015, 05:21 AM
  3. Excel 2010 - Copying sheet with protection manually, protection stays... not with VBA
    By AdamParker in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-02-2012, 12:38 PM
  4. Cell Protection
    By KennyG in forum Excel General
    Replies: 3
    Last Post: 03-02-2011, 12:10 PM
  5. Autofilter and sheet protection problems
    By EdMac in forum Excel General
    Replies: 4
    Last Post: 05-17-2007, 05:36 AM
  6. Command Button protection problems????
    By Chris Watson in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-25-2006, 11:30 AM
  7. [SOLVED] Cell Protection
    By Roger Govier in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 09-06-2005, 03:05 PM

Bookmarks

Posting Permissions

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

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1