Consulting

Results 1 to 6 of 6

Thread: Converting amounts to fixed-length

  1. #1
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location

    Question Converting amounts to fixed-length

    In column C I have amounts like:
    350.62
    64.63
    165.06
    92.83
    374.87
    69.21
    45.83
    333.12
    454.03
    334.3

    Which I need converting to:

    00000035062
    00000006463
    00000016506
    00000009283
    00000037487
    00000006921
    00000004583
    00000033312
    00000045403
    00000033430 - this one was 334.3 (need the zero on the end in the conversion)

    The amounts should be formatted so that they are 11 characters in length
    without any decimal places in and zeros at the front to make up the length.
    How many amounts in column A will vary.

    Can anyone tell me a VBA macro in which do this please?.

    Thanks,

    Marcster.

  2. #2
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by Marcster
    In column C I have amounts like:
    350.62
    64.63
    165.06
    92.83
    374.87
    69.21
    45.83
    333.12
    454.03
    334.3

    Which I need converting to:

    00000035062
    00000006463
    00000016506
    00000009283
    00000037487
    00000006921
    00000004583
    00000033312
    00000045403
    00000033430 - this one was 334.3 (need the zero on the end in the conversion)

    The amounts should be formatted so that they are 11 characters in length
    without any decimal places in and zeros at the front to make up the length.
    How many amounts in column A will vary.

    Can anyone tell me a VBA macro in which do this please?.

    Thanks,

    Marcster.
    this could be done without VBA. It would be a bit complicated, but could be done. However, since you asked about VBA, see the attached file. Select the target cells and click on the button
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  3. #3
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Hi Marcster,

    First off,you don't need to use VBA for this.. You can enter the following formula for the cells you need, then use copy/paste special/values:
    =TEXT(C1*100,"00000000000")
    But if you really want a vba solution,

    Dim TheColumn As Range
    Set TheColumn = Columns("C")
    TheColumn.Offset(0, 1).Insert
     With Range(TheColumn.Cells(1), TheColumn.Cells(65536).End(xlUp))
      .Offset(0, 1).FormulaR1C1 = "=TEXT(RC[-1]*100,""00000000000"")"
      .Offset(0, 1).Copy
      .PasteSpecial xlPasteValues
      .Offset(0, 1).EntireColumn.Delete
     End With
    Matt

  4. #4
    VBAX Expert
    Joined
    Feb 2005
    Posts
    929
    Location
    Quote Originally Posted by mvidas
    Hi Marcster,

    First off,you don't need to use VBA for this.. You can enter the following formula for the cells you need, then use copy/paste special/values:
    =TEXT(C1*100,"00000000000")
    But if you really want a vba solution,

    Dim TheColumn As Range
    Set TheColumn = Columns("C")
    TheColumn.Offset(0, 1).Insert
     With Range(TheColumn.Cells(1), TheColumn.Cells(65536).End(xlUp))
      .Offset(0, 1).FormulaR1C1 = "=TEXT(RC[-1]*100,""00000000000"")"
      .Offset(0, 1).Copy
      .PasteSpecial xlPasteValues
      .Offset(0, 1).EntireColumn.Delete
     End With
    ]Matt
    certainly much more elegant solutions than mine. I wonder why I did not think to multipjy by 100 to get rid of the decimal point and solve the lack of hundredths place problem. Must be getting old. Or maybe it was that 30 foot branch that almost fell on me an hour ago? Yes, I wil blame it on that.
    "It's not just the due date that's important, it's also the do date" [MWE]

    When your problem has been resolved, mark the thread SOLVED by clicking on the Thread Tools dropdown menu at the top of the thread.

  5. #5
    Knowledge Base Approver
    The King of Overkill! VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    I'm not surprised with that wind out there! Random bouts of torrential rain and 40-50 mph wind.. yeah we both chose the right place to live

  6. #6
    VBAX Mentor Marcster's Avatar
    Joined
    Jun 2005
    Posts
    434
    Location
    Thanks for the replies ,
    Now does what I want, thanks again.

    Marcster

Posting Permissions

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