Consulting

Results 1 to 13 of 13

Thread: strip decimal point but keep cents

  1. #1

    Question strip decimal point but keep cents

    From an excel file i receive, i'm to save as a .txt file and i need the decimal places in my text file, but not the "." How can i strip the period out of cells, while still maintaining the decimal places? thanks

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Do a global Find and Replace, replacing . with nothing

  3. #3
    If you're talking about the Replace option in excel, i've tried that, but when i enter . at the find prompt, i keep getting 'microsoft office excel cannot find the data you're searching for.' Or, am i completely stupid and you're talking about doing this w/vb? thanks.

  4. #4

    Wink

    i got it. i had to change the decimal separator from . to a blank. Thanks for your help.

  5. #5
    still didn't do it for me because i don't want the extra blank in there either. do you know how to read cell contents from right to left so i can find the decimal in the 3rd position and delete it?

  6. #6
    VBAX Regular
    Joined
    Mar 2005
    Location
    Helena, MT
    Posts
    90
    Location
    Can't you just multiply your data by 100 before exporting to the text file?

    lenze

  7. #7
    DUH!!! thanks, lenze. I also got it to work using SUBSTITUTE. I think i need to go back to bed and start over today..

  8. #8
    okay, now how can i code the worksheet to do all this when it opens? The * by 100 will require an IF statement to return a blank if the cell is 0, as the text file is supposed to only contain > 0 numbers (this is for a journal entry and is related to my 3/16 post, but i've had to resort to using a different source s/sheet than the one mentioned in that posting). so, what i need to do is:

    1. open sheet and loop through the records, looking at certain cells in each record (ex. a1 & a2, b1 & b2, c1 & c2, etc) and for those numeric cells, apply my conditional * by 100, then OVERWRITE the contents of the cell with the value returned by the IF stmt. make sense?

  9. #9
    VBAX Regular
    Joined
    Mar 2005
    Location
    Helena, MT
    Posts
    90
    Location
    Maybe something like this
    Sub ConVert()
        Dim cl As Range
        For Each cl In Selection
        If cl.Value <> 0 Then
            cl.Value = cl.Value * 100
            cl.NumberFormat = "General"
            Else: cl.Value = ""
        End If
        Next cl
    End Sub
    Identify or define Selection as required.

    lenze

  10. #10
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by lenze
    Maybe something like this
    Sub ConVert()
        Dim cl As Range
        For Each cl In Selection
        If cl.Value <> 0 Then
            cl.Value = cl.Value * 100
            cl.NumberFormat = "General"
            Else: cl.Value = ""
        End If
        Next cl
    End Sub
    Identify or define Selection as required.

    lenze
    Am I missing something? Isn't 0*100 still 0?

  11. #11
    VBAX Regular
    Joined
    Mar 2005
    Location
    Helena, MT
    Posts
    90
    Location
    Am I missing something? Isn't 0*100 still 0?
    Yes, but the OP wants 0 to be a Blank

    lenze

  12. #12
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Quote Originally Posted by lenze
    Yes, but the OP wants 0 to be a Blank

    lenze
    But by doing nothing with it it stays as 0

  13. #13
    VBAX Regular
    Joined
    Mar 2005
    Location
    Helena, MT
    Posts
    90
    Location
    But by doing nothing with it it stays as 0
    Maybe I'm missing something. Doesn't the line
    Else: cl.Value = ""
    fix that?

    lenze

Posting Permissions

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