Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Formatting a Column

0

I am using the 

 Range("U2"), Range("U2").End(xlDown)).NumberFormat = "#,##0"

to format column U in a 15K row report.  It works on everything except for 4 non-consecutive rows. Row 2788, Row 2792, Row 5480, Row 11916

The numbers not formatted are 12840, 3054, 1455, and 3295.  All of the other rows containing a number in the thousands are formatted correctly.  There are numerous blank rows.

I am at a loss as to why the code does not work for the whole column.

Answer
Discuss

Discussion

As an additional note.  The report that is generated returns the whole column as an unformatted number, but those four cells are returned as General.  How would I be able to search for those (General) and transpose to number so the cells can be formatted properly?
rappj (rep: 4) Feb 26, '24 at 3:54 pm
I used the Cell function and that returned 416 rows with the General format.  Only 4 rows were over 1,000 which is what I was wanting to format.  Since the report is generated in Access, I would like to be able to change the format to number and then format to thousands.  I believe that is in one of the lessons, but any insight is appreciated.
rappj (rep: 4) Feb 26, '24 at 4:19 pm
Add to Discussion

Answers

0
Selected Answer

Hi Rappj and welcome to the Forum.

Try this instead:

Range("U2:U" & Range("U" & Rows.Count).End(xlUp).Row).NumberFormat = "#,##0"

(Where the bit in bold finds the last used row in column U)

It should format all the used cells (and any blank or non-consecutive cells in between). If the column was previously formatted as General, cells below the last row will remain General.

If instead you want to format the entire column, you can use:

Columns("U").NumberFormat = "#,##0

Hope this fixes your problem. If so, please be sure to mark this Answer as Selected.

Discuss

Discussion

Thanks.  I will test it tomorrow.  Done for the day.  I will be sure to mark answered when it works (Confident it will).  Thanks.
rappj (rep: 4) Feb 26, '24 at 4:22 pm
Glad that helped. Thanks for selecting my Answer, Rappj.
John_Ru (rep: 6142) Feb 27, '24 at 9:14 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login