Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 123
Default macro to disallow shading in certain columns

i have a spreadsheet that is protected so i have a macro to allow users to
shade or unshade cells. The macro basically says if the cell is no-color,
shade green, if its already green shade it no-color, if its any other color
already, then don't allow to shade over.

now they use it to shade anything they can so i need to limit it to select
columns.
for simplicity, say my spreadsheet is A:Z, they are allowed to shade in
columns F, k, P-T and X-Z. can some one advise me on how to modify my macro?
thanks, Tami


With Selection.Interior
If .ColorIndex = 35 Then
.ColorIndex = xlNone
Else
If .ColorIndex = xlNone Then
.ColorIndex = 35
Else
MsgBox ("Error: One or more of the cells you highlighted cannot
be shaded.")
End If
End If
End With

End Sub



  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default macro to disallow shading in certain columns

Maybe something like:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRng As Range
Dim RngToInspect As Range
Dim wks As Worksheet
Dim FoundAnError As Boolean

Set wks = ActiveSheet

With wks
Set RngToInspect = .Range("F:F,K:K,P:T,x:z")
Set myRng = Nothing
On Error Resume Next
Set myRng = Intersect(Selection, RngToInspect)
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "selection not in authorized range"
Exit Sub
End If

.Unprotect

FoundAnError = False
For Each myCell In myRng.Cells
With myCell.Interior
If .ColorIndex = 35 Then
.ColorIndex = xlNone
Else
If .ColorIndex = xlNone Then
.ColorIndex = 35
Else
FoundAnError = True
End If
End If
End With
Next myCell

.Protect

End With

If FoundAnError = True Then
MsgBox "Error: One or more of the cells you " _
& "highlighted cannot be shaded."
End If

End Sub


Tami wrote:

i have a spreadsheet that is protected so i have a macro to allow users to
shade or unshade cells. The macro basically says if the cell is no-color,
shade green, if its already green shade it no-color, if its any other color
already, then don't allow to shade over.

now they use it to shade anything they can so i need to limit it to select
columns.
for simplicity, say my spreadsheet is A:Z, they are allowed to shade in
columns F, k, P-T and X-Z. can some one advise me on how to modify my macro?
thanks, Tami

With Selection.Interior
If .ColorIndex = 35 Then
.ColorIndex = xlNone
Else
If .ColorIndex = xlNone Then
.ColorIndex = 35
Else
MsgBox ("Error: One or more of the cells you highlighted cannot
be shaded.")
End If
End If
End With

End Sub


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 123
Default macro to disallow shading in certain columns

Dave,
Pure genius! thank you.
happy holidays,
Tami

"Dave Peterson" wrote:

Maybe something like:

Option Explicit
Sub testme()

Dim myCell As Range
Dim myRng As Range
Dim RngToInspect As Range
Dim wks As Worksheet
Dim FoundAnError As Boolean

Set wks = ActiveSheet

With wks
Set RngToInspect = .Range("F:F,K:K,P:T,x:z")
Set myRng = Nothing
On Error Resume Next
Set myRng = Intersect(Selection, RngToInspect)
On Error GoTo 0

If myRng Is Nothing Then
MsgBox "selection not in authorized range"
Exit Sub
End If

.Unprotect

FoundAnError = False
For Each myCell In myRng.Cells
With myCell.Interior
If .ColorIndex = 35 Then
.ColorIndex = xlNone
Else
If .ColorIndex = xlNone Then
.ColorIndex = 35
Else
FoundAnError = True
End If
End If
End With
Next myCell

.Protect

End With

If FoundAnError = True Then
MsgBox "Error: One or more of the cells you " _
& "highlighted cannot be shaded."
End If

End Sub


Tami wrote:

i have a spreadsheet that is protected so i have a macro to allow users to
shade or unshade cells. The macro basically says if the cell is no-color,
shade green, if its already green shade it no-color, if its any other color
already, then don't allow to shade over.

now they use it to shade anything they can so i need to limit it to select
columns.
for simplicity, say my spreadsheet is A:Z, they are allowed to shade in
columns F, k, P-T and X-Z. can some one advise me on how to modify my macro?
thanks, Tami

With Selection.Interior
If .ColorIndex = 35 Then
.ColorIndex = xlNone
Else
If .ColorIndex = xlNone Then
.ColorIndex = 35
Else
MsgBox ("Error: One or more of the cells you highlighted cannot
be shaded.")
End If
End If
End With

End Sub


--

Dave Peterson
.

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
Macro for Shading and Unshading Tami Excel Worksheet Functions 4 September 24th 09 08:22 PM
Shading row based on value in one of its columns EAPS Excel Discussion (Misc queries) 1 July 14th 09 10:19 PM
SHADING OF SELECTED ROWS & COLUMNS DESJAL Excel Discussion (Misc queries) 1 December 14th 08 07:09 PM
Macro for shading Atomic Excel Worksheet Functions 5 June 3rd 08 06:32 PM
sort columns, but not shading on-a-mission New Users to Excel 3 February 16th 06 06:06 PM


All times are GMT +1. The time now is 04:18 AM.

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"