Toggle Button to Change Font/fill color/ border color in rows

mrdanielatkins

New Member
Joined
May 21, 2018
Messages
13
Hello,

I'll start by saying I'm a noob when it comes to VBA coding in excel, but I'm trying to learn. Hoping you guys could help me code a toggle button. When the button is depressed I would like the font, fill color, and border to be white in rows 23-35, on that worksheert, so it is not visible when the document is printed. When the toggle is not pressed I'd like for it to go back to how it was.

I appreciate any help you can provide.

Thanks,
 

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Would simply hiding those rows be ok?
 
Upvote 0
Unfortunately, I can't do that. I have another button built into the worksheet with that function, so I think I could manage that code. The .font is throwing me off on this one.
 
Upvote 0
How about
Code:
Private Sub ToggleButton1_Click()
With Range("23:35")
   .Font.Color = IIf(Me.ToggleButton1, 16777215, [COLOR=#ff0000]1[/COLOR])
   .Interior.Color = IIf(Me.ToggleButton1, 16777215, [COLOR=#ff0000]45678[/COLOR])
   .Borders.Color = IIf(Me.ToggleButton1, 16777215, [COLOR=#ff0000]1[/COLOR])
End With
End Sub
you'll need to change the values in red to what ever colour you need
 
Upvote 0
How about
Code:
Private Sub ToggleButton1_Click()
With Range("23:35")
   .Font.Color = IIf(Me.ToggleButton1, 16777215, [COLOR=#ff0000]1[/COLOR])
   .Interior.Color = IIf(Me.ToggleButton1, 16777215, [COLOR=#ff0000]45678[/COLOR])
   .Borders.Color = IIf(Me.ToggleButton1, 16777215, [COLOR=#ff0000]1[/COLOR])
End With
End Sub
you'll need to change the values in red to what ever colour you need




Great! That worked in changing the colors when the button is clicked, when I unclick, however, everything defaults back to black. Is there additional code I can add to return things back to the way they were? I have a few different colors in these cells ATM.
 
Upvote 0
I have a few different colors in these cells ATM.
Do you mean that the font/fill/border colours vary from cell to cell?
Or is it that the text is always the same colour, but different to the border colour?
 
Upvote 0
See Screen grab Below. I'm trying to make that estimating table, in those rows disappear with the click of a button, however in most instances it can stay on the sheet. The rows need to remain as this is going to be a locked down workbook that needs to be relatively dummy-proof, and is already formatted to print correctly. I'm open to other suggestions if there is a better way to approach this.



2ay2aw.jpg
[/URL]
 
Upvote 0
The simplest way would be to hide those rows, so that they don't print. But I don't know how that would affect your current setup.
The code for which would be
Code:
Private Sub ToggleButton1_Click()
   ActiveSheet.Protect "password", userinterfaceonly:=True
   Rows("23:35").Hidden = Me.ToggleButton1
End Sub
 
Upvote 0
The simplest way would be to hide those rows, so that they don't print. But I don't know how that would affect your current setup.
The code for which would be
Code:
Private Sub ToggleButton1_Click()
   ActiveSheet.Protect "password", userinterfaceonly:=True
   Rows("23:35").Hidden = Me.ToggleButton1
End Sub


I'm going to make this work. Thanks for the help.
 
Upvote 0

Forum statistics

Threads
1,223,895
Messages
6,175,257
Members
452,625
Latest member
saadat28

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