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

Save Often
If you start asking yourself if now is a good time to save your Excel workbook, the answer is Yes
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,224,823
Messages
6,181,185
Members
453,020
Latest member
Mohamed Magdi Tawfiq Emam

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