Share via

Move negative sign help _ Macro

Anonymous
2015-06-18T15:08:32+00:00

Hi!

I would like to take a negative number -10000 and move the negative sign to the right of the number for my system to accept the amount. Could someone help me with a Macro?

If column G is negative then move the negative sign to the right of the number

If column H is negative then move the negative sign to the right of the number

Please and thanks so much!

Nikki

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2015-06-18T16:00:52+00:00

Nekiaholland,

Perhaps this:

Sub move_sign_right()

Dim c As Range, s As String

For Each c In Selection

    If InStr(1, c.Text, "-", vbTextCompare) Then

       s = c.Text

       s = Replace(s, "-", "")

       s = s & "-"

       c.Value = s

    End If

Next

End Sub

--

Regards,

Tom Ogilvy

Was this answer helpful?

0 comments No comments

Answer accepted by question author

Anonymous
2015-06-18T15:23:00+00:00

Are you doing this because you are building say a CSV file and you are just using Excel to set it up and then export it - or does -Excel- still need to see the number as a number and a Negative number at that? 

so assuming you wanted to export a CSV. then

abc abc 76- -56 ABC -76 76- 22- ABC
abc abc 59- -79 ABC -59 59- 51- ABC

I produced column G with :  =ABS(F1)&"-"   and drag filled the formula down.

I produced column H by using the custom number format:  #,##0;#,##0-;0

column C was a paste special values of column G. 

when I exported as CSV I got

abc,abc,76-,-56,ABC,-76,76-,22-,ABC

abc,abc,59-,-79,ABC,-59,59-,51-,ABC

so the right sided hypen/negative sign is preserved whether by formula, stored as text or formatting.

These approaches would be easier than a macro. 

--

Regards,

Tom Ogilvy

Was this answer helpful?

0 comments No comments

9 additional answers

Sort by: Most helpful
  1. Anonymous
    2015-06-18T15:31:17+00:00

    So easy! Thanks so much...

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2015-06-18T15:20:46+00:00

    Hi Nikki,

    Instead of using a macro, why not format the numbers to display the minus sign as you want. Try, for example, a format like:

                          #,##0.00;#,##0.00-

    ===

    Regards,

    Norman

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2015-06-18T15:20:00+00:00

    Hi, go to format cell, custom and enter

    #,##0.00;#,##0.00-

    Was this answer helpful?

    0 comments No comments