Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,339
Default Changing Cells format using VBA

Hi,

Some examples ..

Record a macro and change the cell formats to see the various options.

Range("C1").Select
Selection.NumberFormat = "dd/mm/yyyy hh:mm:ss" 'Date as10/06/2005
Selection.NumberFormat = "dd/mm/yyyy hh:mm" No seconds displayed
Selection.NumberFormat = "dd-mmm-yyyy hh:mm:ss" 'Date as 10-Jun-2005
Range("D1").Select
Selection.NumberFormat = "@" 'Text

HTH

"Amir" wrote:

Hi!

I have some questions about cells formatting:

1. How can I make sure that the format of the data in a certain range/Cell
is Date?
I mean, If I have strings that represent dates, such as "14/5/2006 12:26" in
all the rows in column B, How can I use VBA to make sure that Excel treats
that as date value (and not numbers or text) when i sort the worksheet ?
I know it is possible to do this manually by right clicking the mouse,
choosing "Format Cells", pressing on "Date", then selecting the date type,
but how can I do this with VBA?

2. How I can I control the specific date type (e.g. 14/3/01 versus 14.3.01)
using VBA?

3. How can I do the same but for text format (instead of date)?

Kind regards,
Amir.



  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Changing Cells format using VBA

Hi!

I have some questions about cells formatting:

1. How can I make sure that the format of the data in a certain range/Cell
is Date?
I mean, If I have strings that represent dates, such as "14/5/2006 12:26" in
all the rows in column B, How can I use VBA to make sure that Excel treats
that as date value (and not numbers or text) when i sort the worksheet ?
I know it is possible to do this manually by right clicking the mouse,
choosing "Format Cells", pressing on "Date", then selecting the date type,
but how can I do this with VBA?

2. How I can I control the specific date type (e.g. 14/3/01 versus 14.3.01)
using VBA?

3. How can I do the same but for text format (instead of date)?

Kind regards,
Amir.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 14
Default Changing Cells format using VBA

It works!
Thank you very much!

Regards,
Amir.

"Toppers" wrote in message
...
Hi,

Some examples ..

Record a macro and change the cell formats to see the various options.

Range("C1").Select
Selection.NumberFormat = "dd/mm/yyyy hh:mm:ss" 'Date as10/06/2005
Selection.NumberFormat = "dd/mm/yyyy hh:mm" No seconds displayed
Selection.NumberFormat = "dd-mmm-yyyy hh:mm:ss" 'Date as 10-Jun-2005
Range("D1").Select
Selection.NumberFormat = "@" 'Text

HTH

"Amir" wrote:

Hi!

I have some questions about cells formatting:

1. How can I make sure that the format of the data in a certain
range/Cell
is Date?
I mean, If I have strings that represent dates, such as "14/5/2006 12:26"
in
all the rows in column B, How can I use VBA to make sure that Excel
treats
that as date value (and not numbers or text) when i sort the worksheet ?
I know it is possible to do this manually by right clicking the mouse,
choosing "Format Cells", pressing on "Date", then selecting the date
type,
but how can I do this with VBA?

2. How I can I control the specific date type (e.g. 14/3/01 versus
14.3.01)
using VBA?

3. How can I do the same but for text format (instead of date)?

Kind regards,
Amir.





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
How can I refresh cells after changing the format? JLMHoss Excel Discussion (Misc queries) 3 April 21st 23 10:09 PM
Linking cells with changing format Wombat Excel Discussion (Misc queries) 3 October 6th 09 04:08 PM
Format of Cells Changing on thier own GCC Excel Discussion (Misc queries) 1 July 16th 09 05:38 PM
Format of cells Changing on thier own GCC Excel Worksheet Functions 0 July 16th 09 02:09 PM
Changing a cells format (Time) Keith Excel Discussion (Misc queries) 2 July 21st 06 03:51 PM


All times are GMT +1. The time now is 02:23 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"