Font Selection Based on Variable

TheRogue

New Member
Joined
Aug 3, 2019
Messages
23
I have a Toggle Button, linked to C1, which returns a TRUE/FALSE.
What I want to do is change the font formatting of a <Text Range>, based upon the result in C1
If C1=FALSE, then <Text Range> displays in the default font (Arial, 10), but
If C1=TRUE, the <Text Range> displays in (Times Roman, 12)

I thought that this could easily but w/ Conditional Formatting, but apparently I am mistaken.
 

Excel Facts

Select a hidden cell
Somehide hide payroll data in column G? Press F5. Type G1. Enter. Look in formula bar while you arrow down through G.
You will need a macro do that, do you want to change the format of a cell?
 
Upvote 0
Since CF doesn't allow you to change the font type,
you'd have to do something like this (which, of course, Fluff or someone more VBA experienced will simplify, but this is the general idea):

Code:
Sub ChgFont()
If Range("C1") = True Then
 Range("A1:A10").Font.Name = "Times Roman"
 Range("A1:A10").Font.Size = "12"
 Else
 Range("A1:A10").Font.Name = "Arial"
 Range("A1:A10").Font.Size = "10"
 End If
End Sub
 
Upvote 0
I was thinking of putting the code in the Click event, like
Code:
Private Sub ToggleButton1_Click()
   With Range("D4").Font
      .Name = IIf(Me.ToggleButton1, "Times Roman", "Arial")
      .Size = IIf(Me.ToggleButton1, 12, 10)
   End With
End Sub
 
Upvote 0
That's right, just change it to whatever range you need.
 
Upvote 0
You're welcome & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,223,886
Messages
6,175,196
Members
452,616
Latest member
intern444

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