Macro to Format Values a Standard Excel Option

tatertot

New Member
Joined
Apr 10, 2016
Messages
31
I am wanting to format 3 columns of data in the comma style like I would if I used the Alt+H+K shortcut would format. Instead I cannot find any method that works. I have used "#,###.##" & "Comma" and still the values do not look at all like they would if I used the comma icon on the Home ribbon.

Here is my code:
Worksheets("AUC").Range("L:N").numberformat = "#,##.##"
 

Excel Facts

Which Excel functions can ignore hidden rows?
The SUBTOTAL and AGGREGATE functions ignore hidden rows. AGGREGATE can also exclude error cells and more.
I am wanting to format 3 columns of data in the comma style like I would if I used the Alt+H+K shortcut would format. Instead I cannot find any method that works. I have used "#,###.##" & "Comma" and still the values do not look at all like they would if I used the comma icon on the Home ribbon.

Here is my code:
Worksheets("AUC").Range("L:N").numberformat = "#,##.##"
Hi tatertot, welcome to the boards.

That is a curious issue as generally your code works for me. This is my test data before running the macro:


Excel 2010
LMN
11000.571000.571000.57
21000.571000.571000.57
31000.571000.571000.57
41000.571000.571000.57
51000.571000.571000.57
61000.571000.571000.57
71000.571000.571000.57
81000.571000.571000.57
91000.571000.571000.57
101000.571000.571000.57
111000.571000.571000.57
121000.571000.571000.57
131000.571000.571000.57
141000.571000.571000.57
151000.571000.571000.57
161000.571000.571000.57
171000.571000.571000.57
AUC


Here is my (slightly modified) version of your code:

Code:
Sub UpdateCellFormat()
Sheets("AUC").Range("L:N").NumberFormat = "#,###.##"
End Sub

And here is what the end result looked like:


Excel 2010
LMN
11,000.571,000.571,000.57
21,000.571,000.571,000.57
31,000.571,000.571,000.57
41,000.571,000.571,000.57
51,000.571,000.571,000.57
61,000.571,000.571,000.57
71,000.571,000.571,000.57
81,000.571,000.571,000.57
91,000.571,000.571,000.57
101,000.571,000.571,000.57
111,000.571,000.571,000.57
121,000.571,000.571,000.57
131,000.571,000.571,000.57
141,000.571,000.571,000.57
151,000.571,000.571,000.57
161,000.571,000.571,000.57
171,000.571,000.571,000.57
AUC


What is happening at your end? What does it actually look like when you say "do not look at all like they would if I used the comma icon"?
 
Upvote 0
Hi Fishboy,

What is happening is where there is not values. In those cells, that format is not matching what would happen when I use the "comma" format in Excel. When I use that standard format from Excel options, the blank cells get "-" for 0's. What code would be exactly what would happen if I used the comma option in Excel?
 
Upvote 0
Hi Fishboy,

What is happening is where there is not values. In those cells, that format is not matching what would happen when I use the "comma" format in Excel. When I use that standard format from Excel options, the blank cells get "-" for 0's. What code would be exactly what would happen if I used the comma option in Excel?
Hi tatertot,

I am not entirely I certain I follow. Do you mean that you want with zero or blank values to have a "-" prefix? Can you show me what you expect the final result to look like for:

1. A blank cell?
2. A cell with a zero value?
3. A cell with a positive value?
 
Upvote 0

Forum statistics

Threads
1,215,387
Messages
6,124,633
Members
449,177
Latest member
Sousanna Aristiadou

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