About turning negative number into Text

Kingnight

New Member
Joined
Feb 5, 2011
Messages
38
Hey,

Thanks a lot for your time. I have one question in VBA:

ex: -1

I am trying to turn this one into (1). Here is my forumula in VBA:

neither of those works.


Cells(1, 1) = Application.WorksheetFunction.Text(Cells(1, 1), "0_);(0)")
cells(1,1) = "("&-cells(1,)&")"

Please help!!!:eeek::eeek::eeek::eeek:
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Is this what you want?

Code:
Sub test()
Range("A1").NumberFormat = "0_);(0)"
End Sub
 
Upvote 0
I want to turn -1 into Text (1) rather than number (1) ::confused::confused:. Then I could combinte (1) with other things like ABCD.

Final result will look like: (1)ABCD.

I hope that it is clear~~~:(:(
 
Upvote 0
Code:
Sub test()
With Range("A1")
    If .Value < 1 Then
        .NumberFormat = "@"
        .Value = "(" & Abs(.Value) & ")"
    End If
End With
End Sub
 
Upvote 0
Thanks!!!!, HOTPEPPER. It works.

I guess that problem about my forumula is that excel will not allow me to use "(" & (this has been to positive number?) & ")"

By the way, what is @ as number format?

Thanks :)
 
Upvote 0
I'm checking to see if the value is less than 0, so it will show it as (1). I'm converting it to a positive number so it doesn't show it as (-1)

@ in a number format is Text.
 
Upvote 0
Thanks :)

I guess that given cells(1,1) = -1


Cells(1, 1).Value = "(" & Abs(Cells(1, 1).Value) & ")"


does not work because "(" or ")", for whatever the reason, could be used only if you convert cells(1,1) into TEXT first.

It does not happen to other things like "ABC"&Abs(cells(1,1).value)&"CDE"

Also this only happens in VBA, not in excel.
 
Upvote 0
This does happen in Excel, if you only format the cell to show negative numbers in parentheses, when you use it in a concatenation formula it will show -1, not the formatted version of it.

This is what happens if -1 is only formatted to show as (1)

Excel Workbook
AB
1(1)-1ABC
Sheet1
 
Upvote 0

Forum statistics

Threads
1,224,597
Messages
6,179,813
Members
452,945
Latest member
Bib195

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top