Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default rounding to .5 in VBA

I need help with rounding an answer to either a whole number or a .5 I know
this can be done in Excel and there are limitations with the Round() function
in VBA. I've seen replies stating to use the application.round but how would
I incorporate that into mine? Here is my code:

Private Sub Worksheet_Change(ByVal Target As Range)
' This prorates the # of months'
On Error GoTo ws_exit:
Dim ans As String, DteDiff As Integer
If Not Application.Intersect(Target, Range("$C$25:$C$54")) Is Nothing Then
If UCase(Target.Value) = "Y" Then ' allows for Y and y
With Worksheets("agreement")
ans = InputBox("What is the warranty expiration date #", "Prorate
months", _
Sheets("Agreement").Range("$A$1").Value)
DteDiff = (Range("$L$11") - DateValue(ans)) / 30.42
Target = DteDiff
End With
End If

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,080
Default rounding to .5 in VBA

WorksheetFunction.Round(2 * DteDiff, 0) / 2

if DteDiff is what you are looking to round to the nearest 0.5.

--

Vasant


"Brad" wrote in message
...
I need help with rounding an answer to either a whole number or a .5 I

know
this can be done in Excel and there are limitations with the Round()

function
in VBA. I've seen replies stating to use the application.round but how

would
I incorporate that into mine? Here is my code:

Private Sub Worksheet_Change(ByVal Target As Range)
' This prorates the # of months'
On Error GoTo ws_exit:
Dim ans As String, DteDiff As Integer
If Not Application.Intersect(Target, Range("$C$25:$C$54")) Is Nothing Then
If UCase(Target.Value) = "Y" Then ' allows for Y and y
With Worksheets("agreement")
ans = InputBox("What is the warranty expiration date #", "Prorate
months", _
Sheets("Agreement").Range("$A$1").Value)
DteDiff = (Range("$L$11") - DateValue(ans)) / 30.42
Target = DteDiff
End With
End If



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,560
Default rounding to .5 in VBA

Hi,
I think this will do it for you:
DteDiff = Round((Range("$L$11") - DateValue(ans)) / 30.42,1)
Thanks,

"Brad" wrote:

I need help with rounding an answer to either a whole number or a .5 I know
this can be done in Excel and there are limitations with the Round() function
in VBA. I've seen replies stating to use the application.round but how would
I incorporate that into mine? Here is my code:

Private Sub Worksheet_Change(ByVal Target As Range)
' This prorates the # of months'
On Error GoTo ws_exit:
Dim ans As String, DteDiff As Integer
If Not Application.Intersect(Target, Range("$C$25:$C$54")) Is Nothing Then
If UCase(Target.Value) = "Y" Then ' allows for Y and y
With Worksheets("agreement")
ans = InputBox("What is the warranty expiration date #", "Prorate
months", _
Sheets("Agreement").Range("$A$1").Value)
DteDiff = (Range("$L$11") - DateValue(ans)) / 30.42
Target = DteDiff
End With
End If

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 846
Default rounding to .5 in VBA

Hello David,

Unfortunately that didn't work. Any other ideas? Thanks.

"David" wrote:

Hi,
I think this will do it for you:
DteDiff = Round((Range("$L$11") - DateValue(ans)) / 30.42,1)
Thanks,

"Brad" wrote:

I need help with rounding an answer to either a whole number or a .5 I know
this can be done in Excel and there are limitations with the Round() function
in VBA. I've seen replies stating to use the application.round but how would
I incorporate that into mine? Here is my code:

Private Sub Worksheet_Change(ByVal Target As Range)
' This prorates the # of months'
On Error GoTo ws_exit:
Dim ans As String, DteDiff As Integer
If Not Application.Intersect(Target, Range("$C$25:$C$54")) Is Nothing Then
If UCase(Target.Value) = "Y" Then ' allows for Y and y
With Worksheets("agreement")
ans = InputBox("What is the warranty expiration date #", "Prorate
months", _
Sheets("Agreement").Range("$A$1").Value)
DteDiff = (Range("$L$11") - DateValue(ans)) / 30.42
Target = DteDiff
End With
End If

  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default rounding to .5 in VBA

One way:

DteDiff = Round(2 * (Range("$L$11") - DateValue(ans)) / 30.42, 0) / 2

or, equivalently

DteDiff = Round((Range("$L$11") - DateValue(ans)) / 15.21, 0) / 2



In article ,
"Brad" wrote:

Hello David,

Unfortunately that didn't work. Any other ideas? Thanks.

"David" wrote:

Hi,
I think this will do it for you:
DteDiff = Round((Range("$L$11") - DateValue(ans)) / 30.42,1)
Thanks,

"Brad" wrote:

I need help with rounding an answer to either a whole number or a .5 I
know
this can be done in Excel and there are limitations with the Round()
function
in VBA. I've seen replies stating to use the application.round but how
would
I incorporate that into mine? Here is my code:

Private Sub Worksheet_Change(ByVal Target As Range)
' This prorates the # of months'
On Error GoTo ws_exit:
Dim ans As String, DteDiff As Integer
If Not Application.Intersect(Target, Range("$C$25:$C$54")) Is Nothing
Then
If UCase(Target.Value) = "Y" Then ' allows for Y and y
With Worksheets("agreement")
ans = InputBox("What is the warranty expiration date #", "Prorate
months", _
Sheets("Agreement").Range("$A$1").Value)
DteDiff = (Range("$L$11") - DateValue(ans)) / 30.42
Target = DteDiff
End With
End If

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
ROUNDING FORMULA =ROUND(B12/$B$10,1) ROUNDING TO HIGH SunshineinFt.Myers[_2_] Excel Worksheet Functions 7 March 5th 09 06:41 PM
Rounding Nick C Excel Discussion (Misc queries) 4 July 16th 08 04:26 PM
I need a formula with rounding up & rounding down to the nearest . Tony Kay Excel Worksheet Functions 3 May 29th 07 11:13 PM
Rounding Grant Excel Worksheet Functions 3 March 1st 07 09:55 PM
no rounding JohnLute Excel Worksheet Functions 3 January 16th 07 06:47 PM


All times are GMT +1. The time now is 05:38 PM.

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"