+ Reply to Thread
Results 1 to 4 of 4

Changing Number Format

  1. #1
    Howard Kaikow
    Guest

    Changing Number Format

    I am inserting stuff into some cells as follows:

    shtExcel.Range(Cells(lngRow, 1), Cells(lngRow, 5)) = Split(strBuffer, vbTab)

    Then, I am trying to change some of the cells to numeric format.
    What do I need to use instead of the following?

    shtExcel.Range(Cells(lngFormat, 2), Cells(lngFormat + lngHigh,
    3)).NumberFormat = "#,##0.00"




  2. #2
    Howard Kaikow
    Guest

    Re: Changing Number Format

    "Howard Kaikow" <[email protected]> wrote in message
    news:[email protected]...
    > I am inserting stuff into some cells as follows:
    >
    > shtExcel.Range(Cells(lngRow, 1), Cells(lngRow, 5)) = Split(strBuffer,

    vbTab)
    >
    > Then, I am trying to change some of the cells to numeric format.
    > What do I need to use instead of the following?
    >
    > shtExcel.Range(Cells(lngFormat, 2), Cells(lngFormat + lngHigh,
    > 3)).NumberFormat = "#,##0.00"



    It seems that I need to do the equivalent of "Convert To Number", before
    doing the formatting, but I have not yet found that in the Excel object
    model.



  3. #3
    Howard Kaikow
    Guest

    Re: Changing Number Format

    Hey Howard, here's your answer.

    Add code like the following before setting the format.

    For Each rngCell In shtExcel.Range(Cells(lngFormat, 2),
    Cells(lngFormat + lngHigh, 3))
    rngCell.Value = rngCell.Value
    Next rngCell

    This converts the cells from text to numeric format.



  4. #4
    Peter T
    Guest

    Re: Changing Number Format

    Hi Howard,

    no need to loop

    With shtExcel.Range(Cells(lngRow, 1), Cells(lngRow, 5))
    ..Value = .Value
    End With

    In passing, if shtExcel does not refer to the active sheet you may also need
    to qualify each "Cells" with shtExcel.

    Regards,
    Peter T

    "Howard Kaikow" <[email protected]> wrote in message
    news:[email protected]...
    > Hey Howard, here's your answer.
    >
    > Add code like the following before setting the format.
    >
    > For Each rngCell In shtExcel.Range(Cells(lngFormat, 2),
    > Cells(lngFormat + lngHigh, 3))
    > rngCell.Value = rngCell.Value
    > Next rngCell
    >
    > This converts the cells from text to numeric format.
    >
    >




+ 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