Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Search a range to find cells containing formulas


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

Can anyone help?

Thanks

--
tanktat
-----------------------------------------------------------------------
tanktata's Profile: http://www.excelforum.com/member.php...nfo&userid=459
View this thread: http://www.excelforum.com/showthread.php?threadid=55910

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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" wrote in
message ...

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Search a range to find cells containing formulas


Thanks chaps.

Bob, Yours worked but locked cells that didnt contain formulas. Ha
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

--
tanktat
-----------------------------------------------------------------------
tanktata's Profile: http://www.excelforum.com/member.php...nfo&userid=459
View this thread: http://www.excelforum.com/showthread.php?threadid=55910

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default 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" wrote in
message ...

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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Search a range to find cells containing formulas


Thanks for that, works a treat.

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


--
tanktata
------------------------------------------------------------------------
tanktata's Profile: http://www.excelforum.com/member.php...fo&userid=4598
View this thread: http://www.excelforum.com/showthread...hreadid=559103

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Search range, find value in another col in corresponding row Brent E Excel Discussion (Misc queries) 3 October 1st 08 06:43 PM
Search range of cells, find a value, output adjoining cell. How? nyys Excel Worksheet Functions 3 January 5th 06 01:48 PM
Cells.Find , why it DOESN'T search ? help Andrzej Excel Programming 7 May 29th 05 07:25 AM
Cells.Find , why it DOESN'T search ? help Andrzej New Users to Excel 1 May 22nd 05 02:42 PM
Can Range.Find search a Cells' Text property? clarence_rollins Excel Programming 2 August 25th 03 12:20 AM


All times are GMT +1. The time now is 04:13 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"