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 for Shading and Unshading

I have the following 2 macros as buttons on a custom toobar to Shade or
Unshade cells.

Sub Shade_Cell()
'
' Shade_Cell Macro
'
ActiveSheet.unprotect Password:="paspas"
With Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
ActiveSheet.Protect Password:="paspas", DrawingObjects:=True,
Contents:=True, Scenarios:=True, AllowInsertingRows:=False,
AllowDeletingRows:=False
End With
End Sub


Sub unshade()
'
' unshade Macro

ActiveSheet.unprotect Password:="paspas"
Selection.Interior.ColorIndex = xlNone
ActiveSheet.Protect Password:="paspas", DrawingObjects:=True,
Contents:=True, Scenarios:=True, AllowInsertingRows:=False,
AllowDeletingRows:=False
End Sub

Is there anyway to merge these two macros to one button on my custom
toolbar. So if the range highlighted is already shaded this color (35) then
unshade....if it has no shade then change it to 35.
thanks in advance for any help.
tami


  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 22,906
Default Macro for Shading and Unshading

Sub Toggle_Shade_Cell()

ActiveSheet.Unprotect Password:="paspas"
With Selection.Interior
If .ColorIndex = 35 Then
.ColorIndex = xlNone
Else
.ColorIndex = 35
End If
End With
ActiveSheet.Protect Password:="paspas", DrawingObjects:=True, _
Contents:=True, Scenarios:=True, AllowInsertingRows:=False, _
AllowDeletingRows:=False

End Sub

The pattern = xlsolid is default so not really needed.


Gord Dibben MS Excel MVP

On Thu, 24 Sep 2009 10:00:02 -0700, Tami
wrote:

I have the following 2 macros as buttons on a custom toobar to Shade or
Unshade cells.

Sub Shade_Cell()
'
' Shade_Cell Macro
'
ActiveSheet.unprotect Password:="paspas"
With Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
ActiveSheet.Protect Password:="paspas", DrawingObjects:=True,
Contents:=True, Scenarios:=True, AllowInsertingRows:=False,
AllowDeletingRows:=False
End With
End Sub


Sub unshade()
'
' unshade Macro

ActiveSheet.unprotect Password:="paspas"
Selection.Interior.ColorIndex = xlNone
ActiveSheet.Protect Password:="paspas", DrawingObjects:=True,
Contents:=True, Scenarios:=True, AllowInsertingRows:=False,
AllowDeletingRows:=False
End Sub

Is there anyway to merge these two macros to one button on my custom
toolbar. So if the range highlighted is already shaded this color (35) then
unshade....if it has no shade then change it to 35.
thanks in advance for any help.
tami


  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 123
Default Macro for Shading and Unshading

Thanks Gord, Jessen, Jakob for the prompt response...it worked!
tami

"Gord Dibben" wrote:

Sub Toggle_Shade_Cell()

ActiveSheet.Unprotect Password:="paspas"
With Selection.Interior
If .ColorIndex = 35 Then
.ColorIndex = xlNone
Else
.ColorIndex = 35
End If
End With
ActiveSheet.Protect Password:="paspas", DrawingObjects:=True, _
Contents:=True, Scenarios:=True, AllowInsertingRows:=False, _
AllowDeletingRows:=False

End Sub

The pattern = xlsolid is default so not really needed.


Gord Dibben MS Excel MVP

On Thu, 24 Sep 2009 10:00:02 -0700, Tami
wrote:

I have the following 2 macros as buttons on a custom toobar to Shade or
Unshade cells.

Sub Shade_Cell()
'
' Shade_Cell Macro
'
ActiveSheet.unprotect Password:="paspas"
With Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
ActiveSheet.Protect Password:="paspas", DrawingObjects:=True,
Contents:=True, Scenarios:=True, AllowInsertingRows:=False,
AllowDeletingRows:=False
End With
End Sub


Sub unshade()
'
' unshade Macro

ActiveSheet.unprotect Password:="paspas"
Selection.Interior.ColorIndex = xlNone
ActiveSheet.Protect Password:="paspas", DrawingObjects:=True,
Contents:=True, Scenarios:=True, AllowInsertingRows:=False,
AllowDeletingRows:=False
End Sub

Is there anyway to merge these two macros to one button on my custom
toolbar. So if the range highlighted is already shaded this color (35) then
unshade....if it has no shade then change it to 35.
thanks in advance for any help.
tami



  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 1,533
Default Macro for Shading and Unshading

Hi

It can be done like this:

Sub Shade_Unshade()
'Shade / unshade macro
ActiveSheet.Unprotect Password:="paspas"
If Selection.Interior.ColorIndex = xlNone Then
With Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
End With
Else
Selection.Interior.ColorIndex = xlNone
End If
ActiveSheet.Protect Password:="paspas", DrawingObjects:=True,
Contents:=True, _
Scenarios:=True, AllowInsertingRows:=False, AllowDeletingRows:=False
End Sub

Regards,
Per

"Tami" skrev i meddelelsen
...
I have the following 2 macros as buttons on a custom toobar to Shade or
Unshade cells.

Sub Shade_Cell()
'
' Shade_Cell Macro
'
ActiveSheet.unprotect Password:="paspas"
With Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
ActiveSheet.Protect Password:="paspas", DrawingObjects:=True,
Contents:=True, Scenarios:=True, AllowInsertingRows:=False,
AllowDeletingRows:=False
End With
End Sub


Sub unshade()
'
' unshade Macro

ActiveSheet.unprotect Password:="paspas"
Selection.Interior.ColorIndex = xlNone
ActiveSheet.Protect Password:="paspas", DrawingObjects:=True,
Contents:=True, Scenarios:=True, AllowInsertingRows:=False,
AllowDeletingRows:=False
End Sub

Is there anyway to merge these two macros to one button on my custom
toolbar. So if the range highlighted is already shaded this color (35)
then
unshade....if it has no shade then change it to 35.
thanks in advance for any help.
tami



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 8,520
Default Macro for Shading and Unshading

Hi Tami

Try the below

Sub ShadeUnshade_Cell()
ActiveSheet.Unprotect Password:="paspas"
With Selection.Interior
..ColorIndex = IIf(.ColorIndex = xlNone, 35, xlNone)
If .ColorIndex = 35 Then .Pattern = xlSolid
ActiveSheet.Protect Password:="paspas", DrawingObjects:=True, _
Contents:=True, Scenarios:=True, AllowInsertingRows:=False, _
AllowDeletingRows:=False
End With
End Sub

If this post helps click Yes
---------------
Jacob Skaria


"Tami" wrote:

I have the following 2 macros as buttons on a custom toobar to Shade or
Unshade cells.

Sub Shade_Cell()
'
' Shade_Cell Macro
'
ActiveSheet.unprotect Password:="paspas"
With Selection.Interior
.ColorIndex = 35
.Pattern = xlSolid
ActiveSheet.Protect Password:="paspas", DrawingObjects:=True,
Contents:=True, Scenarios:=True, AllowInsertingRows:=False,
AllowDeletingRows:=False
End With
End Sub


Sub unshade()
'
' unshade Macro

ActiveSheet.unprotect Password:="paspas"
Selection.Interior.ColorIndex = xlNone
ActiveSheet.Protect Password:="paspas", DrawingObjects:=True,
Contents:=True, Scenarios:=True, AllowInsertingRows:=False,
AllowDeletingRows:=False
End Sub

Is there anyway to merge these two macros to one button on my custom
toolbar. So if the range highlighted is already shaded this color (35) then
unshade....if it has no shade then change it to 35.
thanks in advance for any help.
tami




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 Atomic Excel Worksheet Functions 5 June 3rd 08 06:32 PM
Creating a Macro For Shading Rows - Or Should I Use Conditional Formatting? [email protected] Excel Worksheet Functions 3 May 3rd 07 11:41 PM
shading a rowwhen a time is entered but no shading when 0 is enter fomula problems Excel Worksheet Functions 7 October 23rd 05 08:44 PM
Shading cells with a Macro maacmaac Excel Discussion (Misc queries) 1 August 18th 05 03:48 PM
Is there a formula, function or macro that accounts for shading of a cell or row? Jamie Furlong Excel Discussion (Misc queries) 1 August 12th 05 09:55 AM


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