RoundDown Function Not Working In My VBA Code

drmingle

Board Regular
Joined
Oct 5, 2009
Messages
229
Objective: to let solver do its thing, but after solver runs to have the value in C5 to be rounded down.

Example: After solver runs ("C5" = $3,012.63); I need it to display as ("C5" = $3,012).

The below code works for with the exception of the my attempt in red:

Code:
Sub Calc_SingleServDollar()
 
Application.ScreenUpdating = False
If Error Then GoTo SingleServDollar
''Routine performed on SinglePerDieam tab
    With Worksheets("SinglePerDiem")
''Reset Solver Function
        Application.Run "SolverReset"
''Executing Solver Function without pulling standard user report
        Application.Run "SolverOK", "E5", _
                 3, _
                 Range("E4").Value, _
                 "C5"
''Executing Solver Function without pulling standard user report
        Application.Run "SolverSolve", True
                Range("C2").Formula = "=NOW()"
 
'' Message to user declaring the Target Dollars and Optimized Case Rate
        MsgBox Prompt:=.Range("B2").Value & " " & .Range("C2").Value & vbLf & vbLf & _
                       "Target Dollars: " & Format(.Range("E4").Value, "currency") & vbLf & vbLf & _
                       "Optimized Proposed Rate: " & Format(.Range("C5").Value, "currency"), _
               Buttons:=vbOKOnly, _
               Title:="APS Pricer: Single Per Diem"
    End With
 
[COLOR=red]Range("C5") = Application.RoundDown(C5, 0)[/COLOR]
 
Exit Sub
SingleServDollar:
    MsgBox "Error with Solver Function being used within Single Service Dollar."
 
Application.ScreenUpdating = True
End Sub

I am using excel 2007.

All help is appreciated!
 

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
It may be the same thing (same arguments), or may not, but take out the "Application" and it should work.
 
Upvote 0
Range("C5") = Application.RoundDown(C5, 0)

Pass a range to the worksheet function, not C5 (which is probably interpreted here as zero or null):
Code:
Range("C5") = Application.RoundDown(Range("C5"), 0)
 
Upvote 0
Why not just use the VBA function Int?

Code:
Range("C5")=Int(Range("C5"))
 
Upvote 0
:confused: I don't know what I was thinking. Disregard my post. Getting my WS functions and VBA functions mixed up.

Maybe I need a vacation :)

Anyhow, sorry for any trouble I may have caused the OP.
 
Upvote 0
Long day I guess :) ...some days I wonder if I do more harm than good (on here I mean)

Hopefully I don't cause any permanent data loss :(
 
Upvote 0

Forum statistics

Threads
1,217,375
Messages
6,136,187
Members
449,997
Latest member
satyam7054

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