#1   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 79
Default excel spreadsheet

I have created a budget with dollars and cents, however I would like to have
the cell round the number. For instance, if I type in $5.45 I'd like the
cell value to be $5.00; If I type $117.88, I'd like it to read $118.00.
How do I accomplish this?
  #2   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 229
Default excel spreadsheet

You can use this formula:

=MROUND(A1,1)

Where A1 is the cell where you enter the data.

If you want this to happen automatically in the cell you're editing,
you will need a worksheet function like this (paste this in your
worksheet's code module):

Private Sub Worksheet_Change(ByVal Target As Range)
If (Len(Target.Value) And isNumber(Target.Value)) Then
Target.Value = _
Application.WorksheetFunction.MRound(Target.Value, 1)
Target.NumberFormat = _
"_($* #,##0.00_);_($* (#,##0.00);_($* " & _
Chr(34) & " - " & Chr(34) & "??_);_(@_)"
End If
End Sub

Private Function isNumber(num As Variant) As Boolean
Dim temp As Double

On Error Resume Next
temp = num - 1
On Error GoTo 0

isNumber = (Err.Number = 0)
Err.Clear
End Function

Additionally, you may want to define a named range in which you're
entering these figures, so that the event doesn't trigger for
something that's a number but not a budget amount (such as time). I
also put in an autoformat to display the number as currency, and to
ignore blank cells.


On Oct 26, 3:39 pm, Angie wrote:
I have created a budget with dollars and cents, however I would like to have
the cell round the number. For instance, if I type in $5.45 I'd like the
cell value to be $5.00; If I type $117.88, I'd like it to read $118.00.
How do I accomplish this?



  #3   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 229
Default excel spreadsheet

OOPS! I always forget this... sorry. Replace the Sub
Worksheet_Change with the following:

Private Sub Worksheet_Change(ByVal Target As Range)
Dim rng As Excel.Range
Application.EnableEvents = False

For Each rng In Target
If (Len(rng.Value) And isNumber(rng.Value)) Then
rng.Value = _
Application.WorksheetFunction.MRound(rng.Value, 1)
rng.NumberFormat = _
"_($* #,##0.00_);_($* (#,##0.00);_($* " & _
Chr(34) & " - " & Chr(34) & "??_);_(@_)"
End If
Next rng

Application.EnableEvents = True
End Sub


On Oct 26, 4:49 pm, iliace wrote:
You can use this formula:

=MROUND(A1,1)

Where A1 is the cell where you enter the data.

If you want this to happen automatically in the cell you're editing,
you will need a worksheet function like this (paste this in your
worksheet's code module):

Private Sub Worksheet_Change(ByVal Target As Range)
If (Len(Target.Value) And isNumber(Target.Value)) Then
Target.Value = _
Application.WorksheetFunction.MRound(Target.Value, 1)
Target.NumberFormat = _
"_($* #,##0.00_);_($* (#,##0.00);_($* " & _
Chr(34) & " - " & Chr(34) & "??_);_(@_)"
End If
End Sub

Private Function isNumber(num As Variant) As Boolean
Dim temp As Double

On Error Resume Next
temp = num - 1
On Error GoTo 0

isNumber = (Err.Number = 0)
Err.Clear
End Function

Additionally, you may want to define a named range in which you're
entering these figures, so that the event doesn't trigger for
something that's a number but not a budget amount (such as time). I
also put in an autoformat to display the number as currency, and to
ignore blank cells.

On Oct 26, 3:39 pm, Angie wrote:



I have created a budget with dollars and cents, however I would like to have
the cell round the number. For instance, if I type in $5.45 I'd like the
cell value to be $5.00; If I type $117.88, I'd like it to read $118.00.
How do I accomplish this?- Hide quoted text -


- Show quoted text -



  #4   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 8,651
Default excel spreadsheet

=ROUND(A1,0)
--
David Biddulph

"Angie" wrote in message
...
I have created a budget with dollars and cents, however I would like to
have
the cell round the number. For instance, if I type in $5.45 I'd like the
cell value to be $5.00; If I type $117.88, I'd like it to read $118.00.
How do I accomplish this?



  #5   Report Post  
Posted to microsoft.public.excel.misc
external usenet poster
 
Posts: 25
Default excel spreadsheet

Hi Angie.
Simply, try this macro to be pasted in the worksheet's code module, like
Sheet1:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Column < 1 Then Exit Sub 'only column A
If Not IsNumeric(Target.Value) Then
MsgBox "---- Only numbers, please! <----"
Target.Value = ""
Exit Sub
End If
Target.Value = Int(Target.Value + 0.5)
End Sub

Regards,
Eliano


"Angie" wrote:

I have created a budget with dollars and cents, however I would like to have
the cell round the number. For instance, if I type in $5.45 I'd like the
cell value to be $5.00; If I type $117.88, I'd like it to read $118.00.
How do I accomplish this?



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
Import excel spreadsheet into an excel spreadsheet kfletchb Excel Worksheet Functions 2 August 4th 06 12:49 AM
In Excel I want to copy text from spreadsheet to spreadsheet Kris Excel Worksheet Functions 3 June 9th 06 07:58 PM
convert ms works spreadsheet to excel spreadsheet on pda d Excel Discussion (Misc queries) 0 February 20th 06 10:40 AM
conversion of MS Works Spreadsheet to Excel 2002 Spreadsheet Kellie Excel Discussion (Misc queries) 1 March 24th 05 06:31 PM
Is there a way to insert a formula, password or macro in an excel spreadsheet that will automatically delete the spreadsheet? oil_driller Excel Discussion (Misc queries) 1 February 8th 05 09:34 AM


All times are GMT +1. The time now is 04:12 PM.

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

About Us

"It's about Microsoft Excel"