Color Toggle

The Animal

Active Member
Joined
May 26, 2011
Messages
449
Hi.
I would like to create a toggle button but instead of selecting the columns to toggle (as per below "Range("D:E").Columns.Hidden = Not Range("D:E").Columns.Hidden") I would like to toggle on cell color so then you can quickly fill and unfill the cells in row 1 and toggle would use a color value rather than pre-determined columns.
If we use color below RGB
Red: 204
Green: 255
Blue: 204

Sub TogglePartNo()
ActiveSheet.Protect DrawingObjects:=True, Contents:=True, Scenarios:=True _
, AllowFormattingCells:=True, AllowFormattingColumns:=True, _
AllowFormattingRows:=True, AllowInsertingColumns:=True, AllowInsertingRows _
:=True
Range("D:E").Columns.Hidden = Not Range("D:E").Columns.Hidden
End Sub

Any help would be great
Thanks Stephen
 

Excel Facts

Lock one reference in a formula
Need 1 part of a formula to always point to the same range? use $ signs: $V$2:$Z$99 will always point to V2:Z99, even after copying
I am not quite sure what you want but this will toggle a color on and off
Code:
Sub test()

  
 tst = Range(Cells(1, 4), Cells(1, 5)).Interior.ColorIndex
 If tst = 35 Then
 Range(Cells(1, 4), Cells(1, 5)).Interior.ColorIndex = 0
 Else
 Range(Cells(1, 4), Cells(1, 5)).Interior.ColorIndex = 35
 End If
 
End Sub
 
Last edited:
Upvote 0
Thanks for your help
My meaning was that lets say you fill color D1,F1 and H1 with the above fill color then if you run toggle based on that fill color those coloumns will hide and unhide?
 
Upvote 0
try something like this ( untested)
Code:
Sub test()

lastcol = Cells(1, Columns.Count).End(xlToLeft).Column
For i = 1 To lastcol
 tst = Range(Cells(1, i), Cells(1, i)).Interior.ColorIndex
 If tst = 35 Then
 Range(Cells(1, i), Cells(1, i)).Columns.Hidden = Not Range(Cells(1, i), Cells(1, i)).Columns.Hidden
 Else
 Range(Cells(1, i), Cells(1, i)).Columns.Hidden = False
 End If
Next i
End Sub
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,908
Messages
6,175,306
Members
452,633
Latest member
DougMo

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top