Help with VBA code to round up or down

kazbarina

New Member
Joined
Apr 30, 2007
Messages
31
Hi,

Some of my code is below. I am getting a value and storing it into a variable and then multiplying this value by a fixed percentage stored in a cell. For example, the value may be 3, the calculation goes 3 * 10% = the variable then calculates 3.3. For anything that is .5 or above I need to round up i.e. 4. For anythigng that is <.5 I need to round down i.e. 3.

I've tried the round function but it currently returns 0! All help appreciated

Application.ScreenUpdating = False

Dim nRowsChill As Double
Dim nRowsMeat As Double
Dim nRowsProduce As Double
Dim rngStoreNrs As Range
Dim cStore As Range
Dim nUpliftQty As Double
Dim nUpliftRound As Double
Dim nChillQty As Double
Dim nChillUplift As Double
Dim nMeatQty As Double
Dim nMeatUplift As Double
Dim nProduceQty As Double
Dim nProduceUplift As Double

With ActiveSheet
'If no uplift percent keyed, restore original values
If Range("ChillUplift") = 0 And Range("ProduceUplift") = 0 And Range("MeatUplift") = 0 Then
.Range("I8:I" & Range("I65536").End(xlUp).Row).Copy Destination:=Range("F8")
.Range("J8:J" & Range("J65536").End(xlUp).Row).Copy Destination:=Range("G8")
.Range("K8:K" & Range("K65536").End(xlUp).Row).Copy Destination:=Range("H8")
Application.CutCopyMode = False 'clear copy (ergo, clear clipboard)
Else

Set rngStoreNrs = Range("D8", Range("D8").End(xlDown))

'Get current uplift percentages
nRowsChill = Range("ChillUplift").Value
nRowsProduce = Range("ProduceUplift").Value
nRowsMeat = Range("MeatUplift").Value

For Each cStore In rngStoreNrs
nChillQty = cStore.Offset(0, 5).Value 'original chill qty
nUpliftQty = nChillQty + (nChillQty * nRowsChill) ' apply uplift calcuation
MsgBox nUpliftQty

nUpliftQty = Application.Round(nUpliftQty, 1)
MsgBox nUpliftQty
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Hi

I've now tried:

nUpliftRound = Application.WorksheetFunction.Round(nUpliftQty, 0)

It seems to work - I'll just have to keep testing it to see if there are any instances it doesn't
 
Upvote 0

Forum statistics

Threads
1,224,598
Messages
6,179,814
Members
452,945
Latest member
Bib195

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