Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Round up to nearest multiple of 5

I am writing a macro and I need it to take a number and round it up to
the nearest multiple of 5.

For example:

If the number is 74 the macro would change it to 75
If the number is 65.7 the macro would change it to 70 etc.

Can someone show me how to do this?

Thanks,
Kyle
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,441
Default Round up to nearest multiple of 5

Kyle,

Working with numbers on a worksheet: select them first then run

Sub myRoundUp()
Dim myC As Range
For Each myC In Selection
myC.Value = Application.WorksheetFunction.RoundUp(myC.Value * 2, -1) / 2
Next myC
End Sub

working with variables in a macro:

Sub myRoundUp2()
Dim myV As Double
myV = 68.7
myV = Application.WorksheetFunction.RoundUp(myV * 2, -1) / 2
MsgBox myV
End Sub

HTH,
Bernie
MS Excel MVP


wrote in message
...
I am writing a macro and I need it to take a number and round it up to
the nearest multiple of 5.

For example:

If the number is 74 the macro would change it to 75
If the number is 65.7 the macro would change it to 70 etc.

Can someone show me how to do this?

Thanks,
Kyle



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default Round up to nearest multiple of 5

Give this a try (simply select all the cells you want to round in this
manner and run the macro)...

Sub RndToNearest5()
Dim R As Range
For Each R In Selection
If IsNumeric(R.Value) Then R.Value = 5 * (Int(CDbl(R.Value) + 2.5) \ 5)
Next
End Sub

Rick


wrote in message
...
I am writing a macro and I need it to take a number and round it up to
the nearest multiple of 5.

For example:

If the number is 74 the macro would change it to 75
If the number is 65.7 the macro would change it to 70 etc.

Can someone show me how to do this?

Thanks,
Kyle


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Round up to nearest multiple of 5

Thanks for all your help, it's working perfectly now!

Kyle

On Aug 26, 4:44*pm, "Rick Rothstein \(MVP - VB\)"
wrote:
Give this a try (simply select all the cells you want to round in this
manner and run the macro)...

Sub RndToNearest5()
* Dim R As Range
* For Each R In Selection
* * If IsNumeric(R.Value) Then R.Value = 5 * (Int(CDbl(R.Value) + 2..5) \ 5)
* Next
End Sub

Rick

wrote in message

...



I am writing a macro and I need it to take a number and round it up to
the nearest multiple of 5.


For example:


If the number is 74 the macro would change it to 75
If the number is 65.7 the macro would change it to 70 etc.


Can someone show me how to do this?


Thanks,
Kyle- Hide quoted text -


- Show quoted text -


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
How do I round numbers to the nearest multiple of 10 or 5? Wasatch Excel Worksheet Functions 5 May 3rd 23 07:43 PM
How do I round numbers to the nearest multiple of 10 or 5 in the same cell? NOV705 Excel Worksheet Functions 1 November 7th 10 08:54 PM
Round Down to the nearest multiple Xhawk57 Excel Discussion (Misc queries) 3 January 28th 10 02:43 AM
Round to nearest multiple James M Excel Discussion (Misc queries) 4 June 11th 08 10:13 PM
Can you round up numbers to the nearest multiple of ten? Tilly Excel Worksheet Functions 3 June 5th 06 03:52 PM


All times are GMT +1. The time now is 11:31 AM.

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"