How to Bold an Entire Column using VBA

Allienne

New Member
Joined
May 2, 2018
Messages
13
Hello!

I need to bold the entire 'Grand Total' column. Now the number of columns varies so I am trying to find a way to lookup if the column says Grand Total and if so, bold that whole column.

Below is what I have so far. There can be a maximum total of 61 columns (including the Grand Total).

Dim lColumn1 As Long
Dim iCntr1 As Long
lColumn1 = 61
For iCntr = lColumn1 To 1 Step -1
If Cells(1, iCntr1) = "Grand Total" Then
Columns(iCntr1).Font.Bold
End If
Next

Any help would be appreciated!
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Hello!

I need to bold the entire 'Grand Total' column. Now the number of columns varies so I am trying to find a way to lookup if the column says Grand Total and if so, bold that whole column.

Below is what I have so far. There can be a maximum total of 61 columns (including the Grand Total).

Dim lColumn1 As Long
Dim iCntr1 As Long
lColumn1 = 61
For iCntr = lColumn1 To 1 Step -1
If Cells(1, iCntr1) = "Grand Total" Then
Columns(iCntr1).Font.Bold
End If
Next

Any help would be appreciated!
Does this do what you want...
Code:
[table="width: 500"]
[tr]
	[td]Sub BoldGrandTotalColumn()
  With Rows(1).Find("Grand Total", , xlValues, xlWhole, , , False, , False).EntireColumn
    .SpecialCells(xlFormulas).Font.Bold = True
    .SpecialCells(xlConstants).Font.Bold = True
  End With
End Sub[/td]
[/tr]
[/table]
 
Upvote 0
Hi & welcome to MrExcel.
you've got a couple of errors try
Code:
Dim lColumn1 As Long
Dim iCntr1 As Long
lColumn1 = 10
For iCntr[COLOR=#ff0000]1[/COLOR] = lColumn1 To 1 Step -1
   If Cells(1, iCntr1) = "Grand Total" Then
      Columns(iCntr1).Font.Bold [COLOR=#ff0000]= True[/COLOR]
   End If
Next
 
Upvote 0
Fluff,

Your corrections worked! Thanks so much! I'm still learning the VBA rights and wrongs and had no idea I needed to put "= True" behind the .Font.Bold. Also I can't believe I forgot the 1 behind the iCntr. It's part of a larger macro which uses lColumn and iCntr higher up so I couldn't reuse the Dim.
 
Upvote 0
Glad we could help & thanks for the feedback
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,173
Members
453,021
Latest member
Justyna P

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