+ Reply to Thread
Results 1 to 9 of 9

Format a range of cells to numerical values.

  1. #1
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Format a range of cells to numerical values.

    Helo everyone. I have a small scipt of code (courtesy of some developers from this forum) that I have used to automate a task. I have further updated that code to perform additional requirements. However one requirment I need I have not been able to figure.

    As you can tell from the code below the variable constCPSelection is valued as a string and that is fine. However I need the ranges "K:K", "L:L", and "M:M" to be formated as numerical values. I added some code at the end (please see comment), and clearly it does not work. Any suggestions?

    Better put in the worksheet constFileNameMTMReport
    that is created - I need columns K, L and M to be formatted with a comma and two decimal points.

    Please Login or Register  to view this content.
    Last edited by AnthonyWB; 06-06-2011 at 03:15 PM.

  2. #2
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Format a range of cells to numerical values.

    Please read the VBEditor's help item With... End With
    Every property of an object has to be preceded by a dot.

    Please Login or Register  to view this content.



  3. #3
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Format a range of cells to numerical values.

    Try putting a period in front of the word Range (.Range).

    This will tell the macro that the Range to format is on the With ... (workbook??)

    On a second look...

    I think you need to specify what worksheet the range is pointing.

    How about putting
    Please Login or Register  to view this content.
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

  4. #4
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Format a range of cells to numerical values.

    So I tried a couple of things.

    First :

    Please Login or Register  to view this content.
    Which thows the error, "onject doesn't support this property or method"

    I also tried:

    Please Login or Register  to view this content.
    and that did nothing, however it produced no errors.

    I must be missing something?

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Format a range of cells to numerical values.

    I just recorded a macro to do the above and it looks like:
    Please Login or Register  to view this content.
    Maybe you should be uisng Columns instead of Range?

  6. #6
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Format a range of cells to numerical values.

    Thanks Marvin. I will give that a try, but I believe in keeping with god VBA practice .Select should be avoided?

  7. #7
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,168

    Re: Format a range of cells to numerical values.

    I agree but using Columns instead of Range may solve the problem.

  8. #8
    Forum Expert snb's Avatar
    Join Date
    05-09-2010
    Location
    VBA
    MS-Off Ver
    Redhat
    Posts
    5,649

    Re: Format a range of cells to numerical values.

    I don't think so.
    Range isn't a property of a workbook but of a worksheet
    one line suffices:
    Please Login or Register  to view this content.

  9. #9
    Forum Contributor
    Join Date
    03-30-2010
    Location
    Washington DC
    MS-Off Ver
    Excel 2007
    Posts
    458

    Re: Format a range of cells to numerical values.

    Thanks snb, that worked.

+ 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