+ Reply to Thread
Results 1 to 7 of 7

How to uncheck Select Locked Cells & check AllowHyperlinks & AllowAutofilters in VBA code

  1. #1
    Registered User
    Join Date
    08-06-2013
    Location
    Thetford, England
    MS-Off Ver
    Excel 2013 / 365
    Posts
    8

    How to uncheck Select Locked Cells & check AllowHyperlinks & AllowAutofilters in VBA code

    Hello All

    I am extremely new to VBA code & would very much appreciate a little help

    I have set up a worksheet which has a macro for checkboxes & also some code to hide various autofilter arrows. This all works fine until I manually Protect the worksheet. I want to protect the sheet so users can not select locked cells, but can insert Hyperlinks & use Autofilters. With Protection on I get runtime error 1004 when using the check boxes. I have since changed the macro to unprotect & then protect after running, which gets rid of the runtime error but now I can select locked cells & I cant insert Hyperlinks or use the autofilter. I understand that when it is protecting itselg again after running the macro it is "standard" protection setting that are being applied & I therefore need to uncheck the Select Locked Cells & Check The AllowHyperlinks & AllowAutofilters, But I am struggling to get it right.

    Any Ideas

    Many Thanks in advance

    P.S. Please see below my macro & code as it stands

    Private Sub Worksheet_BeforeDoubleClick(ByVal Target As Range, Cancel As Boolean)
    Sheet1.Unprotect Password:=3581
    If (ActiveCell.Column = 22 Or ActiveCell.Column = 25 Or ActiveCell.Column = 28 Or ActiveCell.Column = 35 Or ActiveCell.Column = 40 Or ActiveCell.Column = 43 Or ActiveCell.Column = 47) And _
    ActiveCell.Row > 23 Then
    If ActiveCell.Value = "P" Then
    ActiveCell.Value = ""
    Else
    ActiveCell.Value = "P"
    ActiveCell.Font.Name = "Wingdings 2"
    End If
    ActiveCell.Offset(0, 1).Select
    End If
    Sheet1.Protect Password:=3581
    End Sub
    Sub HideArrowsRange()
    Dim c As Range
    Dim i As Integer
    Dim rng As Range
    Set rng = Range("B22:AW22")
    i = rng.Cells(1, 1).Column - 1
    Application.ScreenUpdating = False

    For Each c In Range("B22:AW22")
    Select Case c.Address
    Case "$B$22", "$C$22", "$D$22", "$F$22", "$G$22", "$H$22", "$I$22", "$J$22", "$K$22", "$L$22", "$M$22", "$N$22", "$P$22", "$R$22", "$T$22", "$U$22", "$W$22", "$X$22", "$Z$22", "$AA$22", "$AC$22", "$AD$22", "$AE$22", "$AF$22", "$AG$22", "$AH$22", "$AJ$22", "$AK$22", "$AL$22", "$AM$22", "$AO$22", "$AP$22", "$AR$22", "$AS$22", "$AT$22", "$AV$22"
    c.AutoFilter Field:=c.Column - i, _
    Visibledropdown:=False
    Case Else
    c.AutoFilter Field:=c.Column - i, _
    Visibledropdown:=True
    End Select
    Next

    Application.ScreenUpdating = True
    Sheet1.Protect Password:=3581
    End Sub

  2. #2
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: How to uncheck Select Locked Cells & check AllowHyperlinks & AllowAutofilters in VBA c

    Hi,

    All you need to do is change the line
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    Please note, I haven't tested this solution with your code, but it runs fine in a test spreadsheet that I just made, so let me know if this works for you

    NB: By allowing filtering, you are allowing users to use a filter that was applied prior to the worksheet being protected. You cannot create or remove an autofilter once the worksheet has been protected.

  3. #3
    Registered User
    Join Date
    08-06-2013
    Location
    Thetford, England
    MS-Off Ver
    Excel 2013 / 365
    Posts
    8

    Re: How to uncheck Select Locked Cells & check AllowHyperlinks & AllowAutofilters in VBA c

    Thank you so much ajryan88, That works great, I thought it was something along those lines. I am finding though, that when I save & close, & then re-open the workbook, I am initially able to select the locked cells (allthough they are still protected) until I either use any one of the checkboxes or in-fact double click anywhere on the sheet. This isn't the end of the world because they are still protected but it would be nice to know why & correct if possible.

    Many Thanks again for responding to my question, it's nice to know there are people out there that will help others in need

  4. #4
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: How to uncheck Select Locked Cells & check AllowHyperlinks & AllowAutofilters in VBA c

    Hi.

    You're very welcome, I'm glad I could help.

    That is weird behaviour, and I have no idea why that is happening, but to overcome it I would suggest placing 3 lines of code in the ThisWorkbook module, inside the Workbook_Open subroutine:
    Please Login or Register  to view this content.
    See if this works for you and let me know.
    Also, please don't forget to mark this thread as solved and add to my reputation when you are satisfied with the outcome

  5. #5
    Registered User
    Join Date
    08-06-2013
    Location
    Thetford, England
    MS-Off Ver
    Excel 2013 / 365
    Posts
    8

    Re: How to uncheck Select Locked Cells & check AllowHyperlinks & AllowAutofilters in VBA c

    Spot on ajryan88, Thanks again, it works a treat

    Ok will do, thanks for the tip

  6. #6
    Valued Forum Contributor
    Join Date
    02-08-2012
    Location
    Newcastle, Australia
    MS-Off Ver
    Excel 2007 and Excel 2010
    Posts
    1,429

    Re: How to uncheck Select Locked Cells & check AllowHyperlinks & AllowAutofilters in VBA c

    You're welcome

  7. #7
    Registered User
    Join Date
    08-06-2013
    Location
    Thetford, England
    MS-Off Ver
    Excel 2013 / 365
    Posts
    8

    Re: How to uncheck Select Locked Cells & check AllowHyperlinks & AllowAutofilters in VBA c

    Hello ajryan88.

    I am currently modifying the enquiry register you helped me with previously & wondered if you might be able to help again.

    The enquiry register has many columns/rows, but I would like to create a data entry form to input data in a range of columns/rows (names, contact details etc): D24:Q5023. The column titles are in row 23, ie. D23:Q23 & all the rows are already numbered in column C, ie. C24:C5023. Is it possible to create a data entry form using VBA, that automatically generates when a user selects any of the cells within the specified range: D24:Q5023, with the column titles as the fields. I would also like to be able to search for data within the form, if possible including the No. (column C) within the search. If this is possible, I would then like to hide some of the columns within that range, but still be able to input the data to be held within those columns on the data entry form. The VBA currently on the sheet is as follows:

    Please Login or Register  to view this content.
    Any help would be greatly appreciated

    Many Thanks in advance

+ 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] Form Control CheckBox check/uncheck via code
    By JasonRay in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 04-18-2013, 02:41 PM
  2. Uncheck "Select Multiple Items" in a Pivot Table Using Code (Excel 2007)
    By delecto in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-02-2009, 12:41 PM
  3. How to Uncheck a Check Box Based on changes in Merged Cells
    By mbrady1973 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 12-18-2008, 04:04 PM
  4. Check or Uncheck range of cells
    By Zimbo in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 02-11-2008, 12:59 AM
  5. Replies: 5
    Last Post: 01-04-2006, 07:15 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