LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default selected range has different cell formatting

Hi all,
I wrote a macro that would change the colour and value of selected cell(s).
I want users to be able to use this macro only if the selected cell(s) are
not locked. (locked cells in the spreadsheet are the ones containing
formulas, and i don't want the users to change that). Here is the code i
wrote:

Sub Approved()

' check that selection is not a protected cell
With Selection
If .Locked = True Then
MsgBox "Sorry! You selected a locked cell."
Exit Sub
End If
End With

ActiveSheet.Unprotect
Selection.Interior.ColorIndex = 35 'Light Green
Selection.value = "Approved"

End Sub

The above code works well when the selection consists of one cell only, or
when the selection consists of a range of cells that all have the same
formatting (either ALL locked, or ALL unlocked). However, when i tested the
code by selecting a range that includes both locked and unlocked cells, the
code didn't seem to know the difference and was run according to the
formatting of the FIRST cell in the selected range.

What do i need to change in order to detect if there is at least one locked
cell in the selected range?

i'm using Excel 2003.

Many thanks
Tendresse


 
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
manually selected Excel cell formatting TomCU Excel Discussion (Misc queries) 1 January 18th 10 12:58 PM
Conditional formatting won't update until cell is selected: Excel TWC Excel Discussion (Misc queries) 3 July 25th 08 03:08 PM
Does the selected cell have a range name? Bill[_41_] Excel Programming 5 March 19th 07 08:02 PM
Referencing the First Cell in Any Selected Range maximouse Excel Programming 4 November 1st 05 03:57 AM
Macro run if and cell in range is selected in VBA Celtic_Avenger[_37_] Excel Programming 1 September 18th 04 03:28 PM


All times are GMT +1. The time now is 08:40 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"