ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   .NumberFormat not getting applied? (https://www.excelbanter.com/excel-programming/411110-numberformat-not-getting-applied.html)

PeteCresswell[_2_]

.NumberFormat not getting applied?
 
---------------------------------------------------------------------------------
Const mFormat_DollarAmount As String = "#,##0.00"


4140 With .Columns(mColNum_FP_AmountOutstanding)
4141 .ColumnWidth = 15
4142 .NumberFormat = mFormat_DollarAmount
4143 .HorizontalAlignment = xlRight
4149 End With
---------------------------------------------------------------------------------

The width and horizontal alignments are working, but
the .NumberFormat is not.

Same problem with date columns:
---------------------------------------------
Const mFormat_Date="mm/dd/yyyy"
..NumberFormat = mFormat_Date
--------------------------------------------

Some limitation on what I can do at the column level?

JLGWhiz

.NumberFormat not getting applied?
 
Can't duplicate the problem. Code works fine for me.

"PeteCresswell" wrote:

---------------------------------------------------------------------------------
Const mFormat_DollarAmount As String = "#,##0.00"


4140 With .Columns(mColNum_FP_AmountOutstanding)
4141 .ColumnWidth = 15
4142 .NumberFormat = mFormat_DollarAmount
4143 .HorizontalAlignment = xlRight
4149 End With
---------------------------------------------------------------------------------

The width and horizontal alignments are working, but
the .NumberFormat is not.

Same problem with date columns:
---------------------------------------------
Const mFormat_Date="mm/dd/yyyy"
..NumberFormat = mFormat_Date
--------------------------------------------

Some limitation on what I can do at the column level?


Dave Peterson

.NumberFormat not getting applied?
 
Any chance that you're looking at the wrong column??? You didn't show what that
..columns(...) referred to.

And two wild guesses...

Do you have merged cells in that range?
What's the style for that range? Is it something special or is it Normal?

Does the code work on a brand new worksheet?

PeteCresswell wrote:

---------------------------------------------------------------------------------
Const mFormat_DollarAmount As String = "#,##0.00"

4140 With .Columns(mColNum_FP_AmountOutstanding)
4141 .ColumnWidth = 15
4142 .NumberFormat = mFormat_DollarAmount
4143 .HorizontalAlignment = xlRight
4149 End With
---------------------------------------------------------------------------------

The width and horizontal alignments are working, but
the .NumberFormat is not.

Same problem with date columns:
---------------------------------------------
Const mFormat_Date="mm/dd/yyyy"
.NumberFormat = mFormat_Date
--------------------------------------------

Some limitation on what I can do at the column level?


--

Dave Peterson

Ron Rosenfeld

.NumberFormat not getting applied?
 
On Sat, 17 May 2008 08:51:34 -0700 (PDT), PeteCresswell
wrote:

---------------------------------------------------------------------------------
Const mFormat_DollarAmount As String = "#,##0.00"


4140 With .Columns(mColNum_FP_AmountOutstanding)
4141 .ColumnWidth = 15
4142 .NumberFormat = mFormat_DollarAmount
4143 .HorizontalAlignment = xlRight
4149 End With
---------------------------------------------------------------------------------

The width and horizontal alignments are working, but
the .NumberFormat is not.

Same problem with date columns:
---------------------------------------------
Const mFormat_Date="mm/dd/yyyy"
.NumberFormat = mFormat_Date
--------------------------------------------

Some limitation on what I can do at the column level?


You don't post much of your code, so it's hard to know where the problem is.

Some of the possibilities include an improper declaration of the columns
property; use of this code snippet with a function (it would need to be in a
sub).

Here is a short routine demonstrating several different ways of setting formats
for an entire column, none of which match what you have written:

=============================
Option Explicit
Sub colfmt()
Dim c As Range
Set c = Range("a1")
c.EntireColumn.NumberFormat = "mm/dd/yyyy"
Columns(2).NumberFormat = "mm/dd/yy"

With Columns(3)
.NumberFormat = "mm/dd/yy"
.ColumnWidth = 25
.HorizontalAlignment = xlCenter
End With
End Sub
==================================
--ron


All times are GMT +1. The time now is 01:34 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com