+ Reply to Thread
Results 1 to 19 of 19

hide and lock cells with formula using vba

Hybrid View

  1. #1
    Forum Guru (RIP) Marcol's Avatar
    Join Date
    12-23-2009
    Location
    Fife, Scotland
    MS-Off Ver
    Excel '97 & 2003/7
    Posts
    7,216

    Re: hide and lock cells with formula using vba

    Okay that means there are no formulae in that particular worksheet.

    Try this code
    Option Explicit
    
    Sub LockFormulae()
        Dim rngHasFormula As Range
        Dim ws As Worksheet
    
        On Error Resume Next
        For Each ws In ActiveWorkbook.Worksheets
            ws.Unprotect
            Set rngHasFormula = ws.UsedRange.SpecialCells(xlCellTypeFormulas)
            If Err.Number <> 0 Then
                Err.Clear
            Else
                With rngHasFormula
                    .Locked = True
                    .FormulaHidden = True
                End With
            End If
            ws.Protect
        Next
        On Error GoTo 0
    End Sub
    Last edited by Marcol; 10-08-2011 at 09:58 AM.
    If you need any more information, please feel free to ask.

    However,If this takes care of your needs, please select Thread Tools from menu above and set this topic to SOLVED. It helps everybody! ....

    Also
    اس کی مدد کرتا ہے اگر
    شکریہ کہنے کے لئے سٹار کلک کریں
    If you are satisfied by any members response to your problem please consider using the small Star icon bottom left of their post to show your appreciation.

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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