Ranges and font

YoCantu18

Board Regular
Joined
Jul 23, 2008
Messages
51
Hi, I'm having a little problem defining ranges. I want to have one cell Bold and Red, while the other cells are normal font.

With Range("C22")
.Font.ColorIndex = 3
.Font.Bold = True
End With
With Range("C20:C21", "C23:C26")
.Font.ColorIndex = 1
.Font.Bold = False
End With

When I run this, all the cells are normal font

Any help appreciated
Thanks
 

Some videos you may like

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.

Richard Schollar

MrExcel MVP
Joined
Apr 19, 2005
Messages
23,707
The second set of formatting overwirtes the first. Because of the way Range() works, your second code is actually apply standard format to C20:C26, not C20:C21 and C23:C26. Swap them round:

Code:
With Range("C20:C26")
    .Font.ColorIndex = 1
    .Font.Bold = False
End With
With Range("C22")
     .Font.ColorIndex = 3
     .Font.Bold = True
 End With
 

mvptomlinson

Well-known Member
Joined
Mar 10, 2008
Messages
2,638
Perhaps try:
Rich (BB code):
With Range("C22")
        .Font.ColorIndex = 3
        .Font.Bold = True
    End With
    With Union(Range("C20:C21"), Range("C23:C26"))
        .Font.ColorIndex = 1
        .Font.Bold = False
    End With
This way the second formatting statement doesn't overwrite the first.
 

Oaktree

MrExcel MVP
Joined
Jun 20, 2002
Messages
7,994
You could also use

With Application.Union(Range("C20:C21"), Range("C23:C26"))

instead of

With Range("C20:C21", "C23:C26")

edit: I was a little slow on the draw on this one.
 

Watch MrExcel Video

Forum statistics

Threads
1,123,307
Messages
5,600,869
Members
414,411
Latest member
Snowmanaus

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