Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default How to prevent change Numeric value to date format ?

Hi Reader

How to prevent change Numeric value to date format ?

Add Not IsNumeric(Selection.Item(ir, ic).Value) not work.

Sub ChangeYYYYMMDD()
Dim iRows As Long
Dim iColumns As Long
Dim ir As Long
Dim ic As Long
iRows = Selection.Rows.Count
iColumns = Selection.Columns.Count
For ir = 1 To iRows
For ic = 1 To iColumns
If IsDate(Selection.Item(ir, ic).Value) And Not
IsNumeric(Selection.Item(ir, ic).Value) Then
Selection.NumberFormatLocal = "yyyy/mm/dd"
End If
Next ic
Next ir
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default How to prevent change Numeric value to date format ?

You have to understand what date format actually is. It is a number. Date
is the number of days from Jan 1, 1900. So the date is around 39,000. A
date will pass a numeric test.

You may be able to test for the date being a range from a start date to an
end date such as

mydate datevalue("1/1/2000") and mydate < datevalue("12/12/2010")

"moonhk" wrote:

Hi Reader

How to prevent change Numeric value to date format ?

Add Not IsNumeric(Selection.Item(ir, ic).Value) not work.

Sub ChangeYYYYMMDD()
Dim iRows As Long
Dim iColumns As Long
Dim ir As Long
Dim ic As Long
iRows = Selection.Rows.Count
iColumns = Selection.Columns.Count
For ir = 1 To iRows
For ic = 1 To iColumns
If IsDate(Selection.Item(ir, ic).Value) And Not
IsNumeric(Selection.Item(ir, ic).Value) Then
Selection.NumberFormatLocal = "yyyy/mm/dd"
End If
Next ic
Next ir
End Sub

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 36
Default How to prevent change Numeric value to date format ?

On 12$B7n(B7$BF|(B, $Be8a(B11$B;~(B28$BJ,(B, Joel wrote:
You have to understand what date format actually is. It is a number. Date
is the number of days from Jan 1, 1900. So the date is around 39,000. A
date will pass a numeric test.

You may be able to test for the date being a range from a start date to an
end date such as

mydate datevalue("1/1/2000") and mydate < datevalue("12/12/2010")



"moonhk" wrote:
Hi Reader


How to prevent change Numeric value to date format ?


Add Not IsNumeric(Selection.Item(ir, ic).Value) not work.


Sub ChangeYYYYMMDD()
Dim iRows As Long
Dim iColumns As Long
Dim ir As Long
Dim ic As Long
iRows = Selection.Rows.Count
iColumns = Selection.Columns.Count
For ir = 1 To iRows
For ic = 1 To iColumns
If IsDate(Selection.Item(ir, ic).Value) And Not
IsNumeric(Selection.Item(ir, ic).Value) Then
Selection.NumberFormatLocal = "yyyy/mm/dd"
End If
Next ic
Next ir
End Sub- $Bp,i6Ho0zMQJ8;z(B -


- $Bp}<(Ho0zMQJ8;z(B -


Thank. I just using VarType to test the cell type.

Sub ChangeYYYYMMDD()
'~~ 2007/12/07 moonhk
Dim iRows As Long
Dim iColumns As Long
Dim ir As Long
Dim ic As Long
Dim k
iRows = Selection.Rows.Count
iColumns = Selection.Columns.Count
For ir = 1 To iRows
For ic = 1 To iColumns
If VarType(Selection.Item(ir, ic)) = vbDate Then
Selection.Item(ir, ic).NumberFormatLocal = "yyyy/mm/dd"
End If
Next ic
Next ir
End Sub
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default How to prevent change Numeric value to date format ?

Not sure. You can use number formatt to return the way a cell is formatted.
the problem is dates can be formated differrent ways and number can be
formatted diferent ways. therefore, you have a lot of testing you may have
to do.

"moonhk" wrote:

On 12月7日, 上午11時28分, Joel wrote:
You have to understand what date format actually is. It is a number. Date
is the number of days from Jan 1, 1900. So the date is around 39,000. A
date will pass a numeric test.

You may be able to test for the date being a range from a start date to an
end date such as

mydate datevalue("1/1/2000") and mydate < datevalue("12/12/2010")



"moonhk" wrote:
Hi Reader


How to prevent change Numeric value to date format ?


Add Not IsNumeric(Selection.Item(ir, ic).Value) not work.


Sub ChangeYYYYMMDD()
Dim iRows As Long
Dim iColumns As Long
Dim ir As Long
Dim ic As Long
iRows = Selection.Rows.Count
iColumns = Selection.Columns.Count
For ir = 1 To iRows
For ic = 1 To iColumns
If IsDate(Selection.Item(ir, ic).Value) And Not
IsNumeric(Selection.Item(ir, ic).Value) Then
Selection.NumberFormatLocal = "yyyy/mm/dd"
End If
Next ic
Next ir
End Sub- 隱藏被引用文* -


- 顯示被引用文* -


Thank. I just using VarType to test the cell type.

Sub ChangeYYYYMMDD()
'~~ 2007/12/07 moonhk
Dim iRows As Long
Dim iColumns As Long
Dim ir As Long
Dim ic As Long
Dim k
iRows = Selection.Rows.Count
iColumns = Selection.Columns.Count
For ir = 1 To iRows
For ic = 1 To iColumns
If VarType(Selection.Item(ir, ic)) = vbDate Then
Selection.Item(ir, ic).NumberFormatLocal = "yyyy/mm/dd"
End If
Next ic
Next ir
End Sub

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
CHANGE TEXT DATE TO NUMERIC DATE slf Excel Worksheet Functions 5 January 5th 10 10:20 AM
Format of column need to change back to Alpha not numeric nadine Excel Discussion (Misc queries) 2 April 26th 07 10:02 PM
Date in numeric format mohd21uk via OfficeKB.com New Users to Excel 2 May 18th 06 04:51 AM
Date in numeric format mohd21uk via OfficeKB.com New Users to Excel 1 May 16th 06 03:00 AM
Change number (in text format) to numeric format Pam Excel Discussion (Misc queries) 5 October 24th 05 07:45 PM


All times are GMT +1. The time now is 05:09 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright 2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"