Consulting

Results 1 to 6 of 6

Thread: Set field lengths

  1. #1
    VBAX Regular
    Joined
    Feb 2007
    Posts
    20
    Location

    Set field lengths

    Need help on something that I have never seen done automatically before. I need to populate cells with numeric data from another sheet (This I can do), what I need help with is:

    Cell value will be a currency amount e.g. 241.65 I need to make this field a certain length by adding zeros to the amount to make the length 15 characters long with a minus sign at the end for the 15th character. e.g. 00000000241.65-

    The thing I need to find out is that all values can be diferent lengths e.g. 1254.25, 10245.85. I need to run a check to see the length and add the appropriate number of zeros to make the 15 characters.

    I need to do this with other cells but these will be alpha characters.

    HELP!!!!

  2. #2
    Administrator
    VP-Knowledge Base
    VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Look at using custom formatting. Is it to be a "genuine" negative value or just look like one?
    Something like
    0000000000000.00"-"

    or

    00;0000000000000.00-;00
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  3. #3
    VBAX Regular
    Joined
    Feb 2007
    Posts
    20
    Location
    The final figure will be a negative. Can using the custom formating check to see what the length of the value is?

    I have a whole sheet where the values will be "Filled", with zeros. Eventually the sheet will be saved as a txt file for an upload to an FTP site for installation to an AS/400 database.

  4. #4
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Did you try it?
    If the data are numbers, the cf inserts the number of zeros required, irrespective of length.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  5. #5
    VBAX Regular
    Joined
    Feb 2007
    Posts
    20
    Location

    Question

    Yes, Cell Formatting worked. Is there a way to do this in VB?

  6. #6
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Try recording a macro to set the CF that you require. That should give you the basic VBA code. I don't know how you intend to apply it.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

Posting Permissions

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