Consulting

Results 1 to 4 of 4

Thread: Sleeper: Auto formatting

  1. #1
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location

    Sleeper: Auto formatting

    I have a problem with using the columns.autofit. In certain rows I have a very large number with about 20 decimal places which changes everytime the report is ran. When importing the text file, it comes out as "Somenumber" + 20. In rows immediatly following this cell, are names I need to autofit. How Can I get around this?
    Peace of mind is found in some of the strangest places.

  2. #2
    VBAX Regular
    Joined
    May 2004
    Location
    Springfield, MO
    Posts
    39
    Excel double precision is limited to 15 digits. Any more than that will be lost to an approximation. So if you want to keep them all (such as for a credit card number), then you'll need to format the cell as text before entering the number.

    When Excel has a very long number to fit in a small column width, it tries to use Scientific notation. I suspect you are seeing something like this: 1.2813E+20 And once this conversion happens, the Format...Columns...AutoFit isn't going to help. Once again, the cure is to format the cell as text before you enter the data.

    One way of entering a long number (as text) into a cell formatted as General is to prefix the number with a single quote:
    '1234567890123456789

    Brad

  3. #3
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    What may be an easier solution is to strip the last 6 characters off of the back of the data in Column A and use that for the cell value. Any ideas?
    Peace of mind is found in some of the strangest places.

  4. #4
    Moderator VBAX Master austenr's Avatar
    Joined
    Sep 2004
    Location
    Maine
    Posts
    2,033
    Location
    I got this to work but it wont work if it tries to pass a cell with alpha text. What is a way around that?

    Sub CheckForNumeric()
    Dim newString As String
    Dim I As Integer
    I = 1
    While Worksheets("Sheet2").Range("A" & I) <> ""
    newString = Worksheets("Sheet2").Range("A" & I)
    newString = Right(newString, Len(newString) - 10)
    Worksheets("Sheet2").Range("A" & I) = newString
    Wend
    End Sub
    Peace of mind is found in some of the strangest places.

Posting Permissions

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