+ Reply to Thread
Results 1 to 6 of 6

Search a range to find cells containing formulas

  1. #1
    Registered User
    Join Date
    01-07-2004
    Location
    Manchester UK
    MS-Off Ver
    Office 2010
    Posts
    73

    Search a range to find cells containing formulas

    I am trying to create a macro that will search through a range and protect any cells that contain formulas of any type.

    Can anyone help?

    Thanks.

  2. #2
    Bob Phillips
    Guest

    Re: Search a range to find cells containing formulas

    For Each Cell In Activesheet.UsedRange
    cell.Locked = Not cell.Hasformula
    Next cell

    Activesheet.Protect

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "tanktata" <tanktata.2ajp4b_1152225302.1672@excelforum-nospam.com> wrote in
    message news:tanktata.2ajp4b_1152225302.1672@excelforum-nospam.com...
    >
    > I am trying to create a macro that will search through a range and
    > protect any cells that contain formulas of any type.
    >
    > Can anyone help?
    >
    > Thanks.
    >
    >
    > --
    > tanktata
    > ------------------------------------------------------------------------
    > tanktata's Profile:

    http://www.excelforum.com/member.php...fo&userid=4598
    > View this thread: http://www.excelforum.com/showthread...hreadid=559103
    >




  3. #3
    Jim Thomlinson
    Guest

    RE: Search a range to find cells containing formulas

    Try this...

    Sub ProtectFormulas()
    Dim rngFormulas As Range
    Dim wks As Worksheet

    Set wks = Sheets("Sheet1")
    On Error Resume Next
    Set rngFormulas = wks.Cells.SpecialCells(xlCellTypeFormulas)
    On Error GoTo 0

    If Not rngFormulas Is Nothing Then rngFormulas.Locked = True
    End Sub
    --
    HTH...

    Jim Thomlinson


    "tanktata" wrote:

    >
    > I am trying to create a macro that will search through a range and
    > protect any cells that contain formulas of any type.
    >
    > Can anyone help?
    >
    > Thanks.
    >
    >
    > --
    > tanktata
    > ------------------------------------------------------------------------
    > tanktata's Profile: http://www.excelforum.com/member.php...fo&userid=4598
    > View this thread: http://www.excelforum.com/showthread...hreadid=559103
    >
    >


  4. #4
    Registered User
    Join Date
    01-07-2004
    Location
    Manchester UK
    MS-Off Ver
    Office 2010
    Posts
    73
    Thanks chaps.

    Bob, Yours worked but locked cells that didnt contain formulas. Had would I change the macro so that cells with formulas are locked?

    Jim, couldnt get yours to work.

    Will these both work with excel 97?

    Thanks again.

  5. #5
    Bob Phillips
    Guest

    Re: Search a range to find cells containing formulas

    Hmm! I will need to look at that.

    Try this instead

    Dim cell As Range

    For Each cell In ActiveSheet.UsedRange
    If cell.HasFormula Then
    cell.Locked = True
    Else
    cell.Locked = False
    End If
    Next cell

    ActiveSheet.Protect

    --
    HTH

    Bob Phillips

    (replace somewhere in email address with gmail if mailing direct)

    "tanktata" <tanktata.2akyq1_1152284409.9098@excelforum-nospam.com> wrote in
    message news:tanktata.2akyq1_1152284409.9098@excelforum-nospam.com...
    >
    > Thanks chaps.
    >
    > Bob, Yours worked but locked cells that didnt contain formulas. Had
    > would I change the macro so that cells with formulas are locked?
    >
    > Jim, couldnt get yours to work.
    >
    > Will these both work with excel 97?
    >
    > Thanks again.
    >
    >
    > --
    > tanktata
    > ------------------------------------------------------------------------
    > tanktata's Profile:

    http://www.excelforum.com/member.php...fo&userid=4598
    > View this thread: http://www.excelforum.com/showthread...hreadid=559103
    >




  6. #6
    Registered User
    Join Date
    01-07-2004
    Location
    Manchester UK
    MS-Off Ver
    Office 2010
    Posts
    73
    Thanks for that, works a treat.

    Had been trying something along those line but it was the 'HasFormula' bit that i didnt have.

+ 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