Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Excel VBA - format a whole column excluding the heading line

I want to format a column but to exclude the first row as this is the header:

My current Code is:

Sheets("Sheet1").Columns(3).NumberFormat = "#,##0"

Thank you.

like image 211
HL8 Avatar asked Mar 16 '12 01:03

HL8


People also ask

How do you select entire column except header first row in Excel VBA?

If your list does not contain any blank cells, you can use the shortcut to select entire column but the first row. Select the header or the first row of your list and press Shift + Ctrl + ↓(the drop down button), then the list has been selected except the first row.

How do I change the format of a column in Excel VBA?

Highlight a cell in the left column of your table. On the Home section of the ribbon, click Conditional Formatting , then New Rule . Use a formula to determine which cells to format . Click Format and set Number to Currency , then click OK.

How do I select a table without the header?

Go to the Table tab on the Ribbon. In the Table Style Options group, select the Header Row check box to hide or display the table headers.


2 Answers

Unless the header is a number you shouldn't need to do this, I don't think. The number format won't affect text (at least not much). But here's a way:

With ThisWorkbook.Sheets("Sheet1")
   .Columns(3).Resize(.Rows.Count - 1, 1).Offset(1, 0).NumberFormat = "#,##0"
End With
like image 106
Doug Glancy Avatar answered Sep 27 '22 22:09

Doug Glancy


Alternatively

Sheets("Sheet1").Range(cells(2,3), cells(2,3).end(xldown)).NumberFormat = "#,##0"

This would select not the entire column, but the range from your first to last non-blank row. If you have empty cells in between your first and last row, this is not an appropriate solution, however.

like image 32
mattboy Avatar answered Sep 27 '22 22:09

mattboy