Consulting

Results 1 to 5 of 5

Thread: Solved: Problem with formats

  1. #1

    Solved: Problem with formats

    Hi there!

    I was developing my macro in excel 2007 and it was working perfectly but when I tried it in the 2003 version it didn't work because of a format conversion!

    The problem is that I write a number in a cell using the percentage format (xlpercentage) so instead of writing 0.05, I write 5.00%

    Later in my program, I need to work with that number but when I do

    MyRate = ActiveCell.Value (MyRate is defined as double and active cell has the percentage number)

    It doesn't work. If I define MyRate as string, the line works but obviously I can't make any calculation with it. Like I said, in the 2007 version there was not any problem.

    Any advice?

    Thanks in advance!

    David

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Post a workbbok that shows the problem.
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Sorry I made a mistake. I used FormatPercentage, not xlPercentage. Here you have an example of what I mean:

    Dim MyRate as Double

    Range("E6").Select
    ActiveCell.Value = FormatPercent(0.05)
    .....
    .....
    .....
    Range("E6").Select
    MyRate = ActiveCell.Value (Now ActiveCell.Value = "5.00%")

    This last line won't work because MyRate is double. If I change it to string, the line works, but afterwards I cannot use the value.

    I was looking for some sort of instruction that will reverse the action FormatPercentage. Some sort of:

    MyRate=UndoFormatPercent(ActiveCell.Value) so that MyRate=0.05

    Thanks!!

  4. #4
    VBAX Guru Kenneth Hobs's Avatar
    Joined
    Nov 2005
    Location
    Tecumseh, OK
    Posts
    4,956
    Location
    Why not use NumberFormat?
    e.g.
    [VBA]Range("A1").NumberFormat="0.00%"
    Range("A1").Value=0.05[/VBA]

  5. #5
    Thanks Kenneth!!

    You solved my problem! Everything works now.

Posting Permissions

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