Consulting

Results 1 to 5 of 5

Thread: move negative sign to the front

  1. #1
    VBAX Regular
    Joined
    May 2007
    Posts
    72
    Location

    move negative sign to the front

    I have this scrape that pulls data of off our mainframe into Excel. The problem is that when the number it pulls is negative, it shows the negative symbol (-) AFTER the number, rather than before. So Excel doesn't recognize that value as a negative number.

    For example:
    -1 shows up as 1-

    How can I move the (-) to the front?

    Thanks!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    =SUBSTITUTE(A1,"-","")*-1
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    VBAX Regular
    Joined
    Aug 2005
    Posts
    42
    Location
    When data are import into EXcel from external, they are normally text based.
    If you using 2003 version, click on the tag smart ( green in color ) at the side of the cell and choose convert to number. It should change the text to number.

    Otherwise try Data>Text to Columns>Next>Next>Advanced, make sure
    Trailing minus for negative numbers is checkmarked > OK>finished

    This will format the cells to numbers.

    regards, xlsops
    Last edited by francis; 09-03-2008 at 11:21 AM.
    Our Greatest Glory is not in never falling, but in rising every time we fall

    There is great satisfaction in building good tools for others to use

  4. #4
    VBAX Regular
    Joined
    May 2007
    Posts
    72
    Location
    What if I want the step of substituting to happen during a macro? Meaning right after it scrapes the values into Excel, how do I add thsi part in. The problem with just using SUBSTITUTE for all of the values is that if something came over as positive without the symbol after it, it would still be made a negative.

    Can you help?
    Thanks!

  5. #5
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    [vba]

    Dim cell As Range

    For Each cell In Columns(1).Cells
    If cell.Value <> "" Then
    If Right(cell.Value, 1) = "-" Then
    cell.Value = -1 * Left(cell.Value, Len(cell.Value) - 1)
    End If
    End If
    Next cell
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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