Switch between two cell colors

Moluccanmom

New Member
Joined
Oct 13, 2016
Messages
41
Hello,

I have a form control button, that hides/unhides rows.
What I would like to do in addition to my code is to change the color of Range("A4:C4") to blue and with the next click back to grey.

Code:
Sub Button1_Click()

Rows("1:3").Hidden = Not Rows("1:3").Hidden
Rows("13:15").Hidden = Not Rows("13:15").Hidden
Rows("27:28").Hidden = Not Rows("27:28").Hidden
Rows("31:39").Hidden = Not Rows("31:39").Hidden

End Sub

Thank you,
Moluccanmom
 

Excel Facts

Easy bullets in Excel
If you have a numeric keypad, press Alt+7 on numeric keypad to type a bullet in Excel.

mumps

Well-known Member
Joined
Apr 11, 2012
Messages
12,673
Office Version
  1. 2013
  2. 2010
Platform
  1. Windows
Maybe:
Code:
Sub Button1_Click()
    Application.ScreenUpdating = False
    If Range("A4:C4").Interior.ColorIndex = 15 Then
        Range("A4:C4").Interior.ColorIndex = 5
    Else
        Range("A4:C4").Interior.ColorIndex = 15
    End If
    Rows("1:3").Hidden = Not Rows("1:3").Hidden
    Rows("13:15").Hidden = Not Rows("13:15").Hidden
    Rows("27:28").Hidden = Not Rows("27:28").Hidden
    Rows("31:39").Hidden = Not Rows("31:39").Hidden
    Application.ScreenUpdating = True
End Sub
 
Upvote 0

Forum statistics

Threads
1,190,953
Messages
5,983,819
Members
439,862
Latest member
FaisalAlTawil

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
Top