Adding formatting to a row

DaveUK

Board Regular
Joined
Jan 24, 2005
Messages
245
Please can someone tell me how (in VBA) to add bold type formatting to any nonempty cell in Row 5 form column B.(Cell B5).

Many thanks
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Press Alt F11
In the left pane, double-click on the sheet this is to be applied to.
Paste this into the right pane:

Private Sub Worksheet_Change(ByVal Target As Range)
[b5].Font.Bold = True
End Sub
 
Upvote 0
Thanks for the reply!!!

However this is not really what i need as new worksheets are created automatically and during this process i want to add the code to do this at design time. If that makes sense.
 
Upvote 0
OK then:

Double-click on "This Workbook" and use this:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
[b5].Font.Bold = True
End Sub
 
Upvote 0
Hi Dave,
If you're looking to do this for row 5 from column B on, then tactps' solution can be amended a bit to this.
It covers text, numeric values and formulas, and executes upon selection of the sheet(s).
Code:
Private Sub Workbook_SheetActivate(ByVal Sh As Object)
On Error Resume Next
[B5:IV5].SpecialCells(xlCellTypeConstants).Font.Bold = True
[B5:IV5].SpecialCells(xlCellTypeFormulas).Font.Bold = True
End Sub
Hope it helps,
Dan
 
Upvote 0
Sorry again but let me reiterate.

I need to apply the formatting programmaticaly. As new worksheets will be added depending on dates. Therefore when a month changes a new worksheet is created and also then i want to format the cells also.

I want to avoid manually selecting and setting the formatting manually.

Thanks anyway
 
Upvote 0
Not sure I understand.
You want to format non empty cells in row 5 (except column A) on all sheets, including any newly created ones, as bold font?
If that's right then the code provided will do that. No need to select & manually format. The only thing that needs to be selected is the sheet one time to execute the formatting code, then it stays. (And the sheet selection can be done programatically if you won't be looking at them before printing or something like that.)

If this isn't what you want can you rephrase your request?

Dan
 
Upvote 0

Forum statistics

Threads
1,203,061
Messages
6,053,307
Members
444,651
Latest member
markkuznetsov1

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