+ Reply to Thread
Results 1 to 29 of 29

Fix Column Character Length

  1. #1
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Fix Column Character Length

    Hi

    How can i fix the character lengths for following columns. I am not sure if there is a way to fix the length or will it be a case of vb edit deleting characters.

    COLUMN CHARACTERS
    A 2
    B 16
    C 6
    D 6
    E 42
    F 14
    G 9
    H 14
    I 6
    J 1
    K 2



    Thanks

    regards
    Last edited by tek9step; 04-19-2010 at 09:52 AM.

  2. #2
    Forum Guru
    Join Date
    03-12-2010
    Location
    Canada
    MS-Off Ver
    2010 and 2013
    Posts
    4,418

    Re: Fix Column Character Length

    Hi

    What do you mean by fixing the character length? Could you elaborate and show what it would look like after fixing the character length

    Abousetta

  3. #3
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Re: Fix Column Character Length

    What i mean is when information entered on the spread sheet it should be of a fix length. for example. Column A cell A2 one should only be able to enter 2 characters or numbers.

    Hope this make more sense.. if not jus give a shout back

    regards

  4. #4
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Fix Column Character Length

    You could apply data validation to each column specifying max len.

    If the cells are already populated then code or formula/copy/paste would be required.
    Cheers
    Andy
    www.andypope.info

  5. #5
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Re: Fix Column Character Length

    Hi Andy tried Data Validation it make sense to use for future thanks.. As i have some historical files which already has data i think a code would be needed ??

    COLUMN CHARACTERS Type
    A 2 Text
    B 16 General
    C 6 General
    D 6 (ddmmyy)
    E 42 General
    F 14 Number
    G 9 Number
    H 14 Number
    I 6 Number
    J 1 General
    K 2 Text



    regards

  6. #6
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Fix Column Character Length

    Something like this to simply truncate the cells contents.

    Please Login or Register  to view this content.
    It would need to be a lot more complex if checking content and type.
    And what do you do with the data if the test fails?

  7. #7
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Re: Fix Column Character Length

    Hi Andy If the test fail will have to go to those particular highlighted cells and manually change them.

  8. #8
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Fix Column Character Length

    Not really that robust but you should get an idea.

    Please Login or Register  to view this content.
    Not sure what you mean by General and Text.
    Also a Number with a length of 14 is vauge. Does that include a decimal place? What about negative values, does the minus sign get included in length?

  9. #9
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Re: Fix Column Character Length

    Sorry Lengths for numbers is inclusive of 2 decimal negative & point.
    By Text i mean general

    Thanks

  10. #10
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Fix Column Character Length

    With numbers is the value in the cell or what is displayed.

    So treat General as Text which means you only need to check length. But again you need to decide whether it's cell value or displayed value.

    What about formula?

    See how complex just defining the problem is.

    So why the need to restrict the data on the sheet? You passing the information to another system.

  11. #11
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Re: Fix Column Character Length

    Hi Andy yess i can see it getting complicated... but im learning the thought process... the information is passed on to me.. so making mine n others life easy before the file comes to me tangled.. which is then handed to IT untangled for test uploading...........

    With numbers there can be formulas in the cells but only want displayed values (so something like paste special value)

    On general it is the displayed value which again im more interested in (so something like paste special value only)

    thanks
    Last edited by tek9step; 04-19-2010 at 09:24 AM.

  12. #12
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Fix Column Character Length

    Then use the .Text property of the cell and simply check for length.

    Please Login or Register  to view this content.

  13. #13
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Re: Fix Column Character Length

    Please Login or Register  to view this content.
    Hi Andy slight problemo on the 4th column some dates are shown as 19/04/2010 and 19-04-2010 (result wanted 190410)

    thanks for teaching

  14. #14
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Fix Column Character Length

    If they are true dates then you can change the NumberFormat for that column


    Please Login or Register  to view this content.

  15. #15
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Re: Fix Column Character Length

    Brilliant works like a jet !!! Thanks Andy

  16. #16
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Re: Fix Column Character Length

    Hi Andy slight issue what if i want to run the macro for rows 4 and below as there were some headers... ???

    thanks

    regards

  17. #17
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Fix Column Character Length

    Please Login or Register  to view this content.

  18. #18
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Re: Fix Column Character Length

    oops got an error trying to follow this logic below
    Please Login or Register  to view this content.

    Please Login or Register  to view this content.
    Last edited by tek9step; 04-19-2010 at 11:35 AM.

  19. #19
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Fix Column Character Lengthf

    Please Login or Register  to view this content.

  20. #20
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Re: Fix Column Character Lengthf

    hi andy where are we specifying the column in the code below as done in previous examples [ UsedRange.Columns(1). ]
    Please Login or Register  to view this content.

  21. #21
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Fix Column Character Length

    4 = Column D

    The cells property has 2 arguments, .Cells( Rownumber , columnnumber )

  22. #22
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Thumbs up Re: Fix Column Character Length

    got it thanks a ton Andy

  23. #23
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Re: Fix Column Character Length

    Hi Andy Getting Slight problem

    Please Login or Register  to view this content.
    Getting bad cell in column F values even though they are within the range and column G format(4 decimal points) is changing not sure why.??

    regards
    Attached Files Attached Files
    Last edited by tek9step; 04-22-2010 at 09:04 AM. Reason: Found the mistake i had made

  24. #24
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Fix Column Character Length

    currently the test for column F is numeric with a length of 14.

    Please Login or Register  to view this content.
    looks like the column contains these values, none of which is 14 characters in size.

    10.90
    10.90
    13.63
    21.80

  25. #25
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Re: Fix Column Character Length

    Hi Andy it should not be more than 14 but can be less (<=14).. so is for rest the columns that is the maximum limit stated in the comments..

    How about G Column it changed its format not sure why.. it was 1.0000

    Thanks
    Last edited by tek9step; 04-22-2010 at 11:39 AM.

  26. #26
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Fix Column Character Length

    Then test for a length greater than 14 only

    Please Login or Register  to view this content.
    The code changes column G, which is a date to numeric format
    Please Login or Register  to view this content.
    maybe you meant
    Please Login or Register  to view this content.

  27. #27
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Re: Fix Column Character Length

    Tested it again rest i think is fixed apart from G column which is numeric number with 4 decimals..(not date that is column D).. I have attached updated file to show the problem with G column.


    Please Login or Register  to view this content.
    Thanks..
    Attached Files Attached Files

  28. #28
    Forum Guru Andy Pope's Avatar
    Join Date
    05-10-2004
    Location
    Essex, UK
    MS-Off Ver
    O365
    Posts
    20,436

    Re: Fix Column Character Length

    then comment out the code which changes the number format of column G

    Please Login or Register  to view this content.
    D is column 4
    G is column 7

  29. #29
    Valued Forum Contributor tek9step's Avatar
    Join Date
    05-27-2009
    Location
    London, England
    MS-Off Ver
    MS 365
    Posts
    389

    Re: Fix Column Character Length

    ahhh sugr i see the problem i didnt change the column.. thanks a ton

+ 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