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
 

Excel Facts

Ambidextrous Undo
Undo last command with Ctrl+Z or Alt+Backspace. If you use the Undo icon in the QAT, open the drop-down arrow to undo up to 100 steps.
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
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,214,866
Messages
6,121,996
Members
449,060
Latest member
mtsheetz

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