+ Reply to Thread
Results 1 to 3 of 3

Format Excel Column via code

  1. #1
    Dale Fye
    Guest

    Format Excel Column via code

    I am unhappy with the Access Transferspreadsheet and OutputTo actions because
    they cutoff text at 255 characters. I've written my own routine to export an
    Access table or query to an excel spreadsheet, and it is working relatively
    well.

    However, I have found that it is not formatting my data correctly.
    Specifically, my Date fields are not being formatted as dates, but as
    integers. Assuming that I have a worksheet object (xlWks), how do I format
    Column 6 to display in a date format ("mm/dd/yyyy")?

    Thanks
    Dale

  2. #2
    mcescher
    Guest

    Re: Format Excel Column via code

    Hi Dale,

    Cycle through the rows in your sheet
    xlWks.Cells(intRow, 6).NumberFormat = "mm/dd/yyyy"

    The quickest way to learn some of these things is to record a macro in
    Excel, and then look at the code it creates. That's helped me MANY
    times B-)

    HTH,
    Chris M.


  3. #3
    Dale Fye
    Guest

    Re: Format Excel Column via code

    Chris,

    I figured out the macro idea, but it recommended something along the lines of:

    wksht.Columns(6).Select
    Selection.FormatNumber "m/d/yyyy"

    When I brought that over to my code, I got an error (don't remember what it
    was) that highlighted "Selection" when I went to debug it.

    I tried:

    wksht.Column(6).Select 'this worked
    With Selection
    .FormatNumber "m/d/yyyy"
    end with

    But that generated an error too; #91, "Object variable or With block
    variable not set"

    I really don't want to do this row by row, but will if I have to. I would
    rather do it as I write the column headers.

    Thanks for the idea.

    Dale

    "mcescher" wrote:

    > Hi Dale,
    >
    > Cycle through the rows in your sheet
    > xlWks.Cells(intRow, 6).NumberFormat = "mm/dd/yyyy"
    >
    > The quickest way to learn some of these things is to record a macro in
    > Excel, and then look at the code it creates. That's helped me MANY
    > times B-)
    >
    > HTH,
    > Chris M.
    >
    >


+ 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