Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 39
Default Negative to zero code

I went in and formatted a cell to: 0;"0";0 so that all negative numbers will
be converted to zero. I have a textbox on a userform that I need to do the
same thing. What code would I use? I tried this but it doesn't work:

txtRemain.Value = Format(txtRemain.Value, "#,#00;""0""")

Any help would be greatly appriciated.

Thanks,
~Gabe


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Negative to zero code

This worked for me:

Sub gh()
Sheets(1).TextBox1.Text = 123.751
MsgBox "OK"
Sheets(1).TextBox1.Text = _
Format(Sheet1.TextBox1.Text, "#,##0.00")
End Sub


"Gabe" wrote in message
...
I went in and formatted a cell to: 0;"0";0 so that all negative numbers
will
be converted to zero. I have a textbox on a userform that I need to do the
same thing. What code would I use? I tried this but it doesn't work:

txtRemain.Value = Format(txtRemain.Value, "#,#00;""0""")

Any help would be greatly appriciated.

Thanks,
~Gabe




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Negative to zero code

Disregard, I misread the posting.


"JLGWhiz" wrote in message
...
This worked for me:

Sub gh()
Sheets(1).TextBox1.Text = 123.751
MsgBox "OK"
Sheets(1).TextBox1.Text = _
Format(Sheet1.TextBox1.Text, "#,##0.00")
End Sub


"Gabe" wrote in message
...
I went in and formatted a cell to: 0;"0";0 so that all negative numbers
will
be converted to zero. I have a textbox on a userform that I need to do
the
same thing. What code would I use? I tried this but it doesn't work:

txtRemain.Value = Format(txtRemain.Value, "#,#00;""0""")

Any help would be greatly appriciated.

Thanks,
~Gabe






  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Negative to zero code

I think you are going to have a hard time getting the TextBox entry to
format as a number. It only deals with text. So any number formats have to
be handled either on the worksheet or in the variable container prior to
posting to the text box. Once in the text box, it is text and while it can
be formatted to look like numbers, it is not numeric, so it cannot tell if a
value is negative.


"Gabe" wrote in message
...
I went in and formatted a cell to: 0;"0";0 so that all negative numbers
will
be converted to zero. I have a textbox on a userform that I need to do the
same thing. What code would I use? I tried this but it doesn't work:

txtRemain.Value = Format(txtRemain.Value, "#,#00;""0""")

Any help would be greatly appriciated.

Thanks,
~Gabe




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,203
Default Negative to zero code

Try this in the text box's _Change event:

Private Sub txtRemain_Change()
If Val(txtRemain) < 0 Then
txtRemain= 0
End If
End Sub


"Gabe" wrote:

I went in and formatted a cell to: 0;"0";0 so that all negative numbers will
be converted to zero. I have a textbox on a userform that I need to do the
same thing. What code would I use? I tried this but it doesn't work:

txtRemain.Value = Format(txtRemain.Value, "#,#00;""0""")

Any help would be greatly appriciated.

Thanks,
~Gabe




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 464
Default Negative to zero code

Private Sub TextBox1_Exit _
(ByVal Cancel As MSForms.ReturnBoolean)
If IsNumeric(TextBox1) Then
If TextBox1.Value < 0 Then
TextBox1 = 0
End If
End If
End Sub



--
Regards
Dave Hawley
www.ozgrid.com
"Gabe" wrote in message
...
I went in and formatted a cell to: 0;"0";0 so that all negative numbers
will
be converted to zero. I have a textbox on a userform that I need to do the
same thing. What code would I use? I tried this but it doesn't work:

txtRemain.Value = Format(txtRemain.Value, "#,#00;""0""")

Any help would be greatly appriciated.

Thanks,
~Gabe



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
code to change color of negative cell [email protected] Excel Programming 1 October 2nd 07 03:48 PM
Negative number morphing to a cell code nickra Excel Worksheet Functions 14 October 1st 07 05:38 AM
Set negative numbers to zero. Do not calculate with negative valu Excel Headache Excel Discussion (Misc queries) 4 September 14th 06 08:56 PM
code wont compare negative numbers correctly evil baby Excel Programming 3 February 28th 06 06:31 PM
Deleting a negative sign from an amount in a list (not trailing negative) Fleming Excel Programming 3 May 7th 04 03:50 PM


All times are GMT +1. The time now is 12:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"