Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make selected column bold and unbold other column in excel

Tags:

excel

vba

I have a Excel Sheet with Macros in it. I want to change the entire column bold when I click on associated button. The click should also unbold all other bold columns.

Public row As Integer, VerticalRange As Range
Sub Sort_Macro_C()
Set VerticalRange = Worksheets("Sheet1").Range("b9:b1000")
Worksheets("Sheet1").Range("c9:c1000").Font.Bold = True
row = Application.WorksheetFunction.CountA(VerticalRange) + 10
Range(Cells(10, 2), Cells(row, 16)).sort Key1:=Range("C9"), Order1:=xlDescending, Header:= _
    xlGuess, OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
    DataOption1:=xlSortTextAsNumbers
End Sub

The above code bolds the entire column but I am not figuring out how to unbold the remaining columns. Any help is appreciated.

Cheers.

like image 494
V_immo Avatar asked Nov 19 '25 09:11

V_immo


1 Answers

Try like this:

Worksheets("Sheet1").Cells.Font.Bold = False
Worksheets("Sheet1").Range("C9:C1000").Font.Bold = True

First it will unbold anything, and then it bolds only the Range("C9:C1000"). If you do not have merged cells, you may use one of the following two:

  • Worksheets("Sheet1").Range("C:C").Font.Bold = True
  • Worksheets("Sheet1").Columns(3).Font.Bold = True

Concerning that you are working with Selection, if you want to bold the all the column of given selection, you may use this:

Selection.EntireColumn.Font.Bold = True
like image 133
Vityata Avatar answered Nov 20 '25 22:11

Vityata



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!