+ Reply to Thread
Results 1 to 3 of 3

Changing Cells format using VBA

  1. #1
    Amir
    Guest

    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.



  2. #2
    Toppers
    Guest

    RE: 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.
    >
    >
    >


  3. #3
    Amir
    Guest

    Re: Changing Cells format using VBA

    It works!
    Thank you very much!

    Regards,
    Amir.

    "Toppers" <[email protected]> wrote in message
    news:[email protected]...
    > 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 to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1