Always roundup the result of an equation instead of rounddown

zack8576

Active Member
Joined
Dec 27, 2021
Messages
271
Office Version
  1. 365
Platform
  1. Windows
part of my macro has a simple equation n /6, when n is < 6, the result is rounded down to 0.

is there any way I can have this result always roundup?
VBA Code:
.Rows(lrNewRows) = Array(Cells(lr, "A"), ".", n \ 6, "F51114", "No", " ", " ", " ", "Purchased", " ", "Primer")

VBA Code:
Sub WrapidSealNine()
    Dim lrNewRows As Long, n As Long, I As Long, lrNew As Long
    lrNewRows = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
    lrNew = ActiveSheet.Range("A" & Rows.Count).End(xlUp).Row
    
    sr = 2
    For I = 2 To lastRow
        If Range("K" & I).Value Like "*9*" And _
           Range("K" & I).Value Like "*Wrapid-Seal*" Then
            n = WorksheetFunction.SumIfs(Range("C" & sr & ":C" & lr), Range("K" & sr & ":K" & lr), "*9"" Wrapid-Seal*")
        End If
    Next I
    
    With Columns("A:K")
            lrNewRows = lrNewRows + 1
        .Rows(lrNewRows) = Array(Cells(lr, "A"), ".", n, "F51041", "No", " ", " ", " ", "Purchased", " ", "9"" Closure")
        If Cells(lrNewRows, "C").Value = 0 Or _
           Cells(lrNewRows, "C").Value < 0 Then
            Rows(lrNewRows).Delete
        End If
            lrNewRows = lrNewRows + 1
        .Rows(lrNewRows) = Array(Cells(lr, "A"), ".", n \ 6, "F51114", "No", " ", " ", " ", "Purchased", " ", "Primer")
        If Cells(lrNewRows, "C").Value = 0 Or _
           Cells(lrNewRows, "C").Value < 0 Then
            Rows(lrNewRows).Delete
        End If
            lrNew = lrNewRows + 1
        .Rows(lrNew) = Array(Cells(lr, "A"), ".", " ", "F51040", "No", " ", " ", " ", "Purchased", " ", "Wrapid-Seal")
        If Cells(lrNewRows, "C").Value = 0 Or _
           Cells(lrNewRows, "C").Value < 0 Then
            Rows(lrNew).Delete
        End If
    End With
End Sub
 

Excel Facts

Links? Where??
If Excel says you have links but you can't find them, go to Formulas, Name Manager. Look for old links to dead workbooks & delete.
Is there a reason you are not considering the ROUNDUP function?
 
Upvote 0
Is there a reason you are not considering the ROUNDUP function?
I havent really used RoundUp before, is this the correct way of using it?

instead of this
VBA Code:
.Rows(lrNewRows) = Array(Cells(lr, "A"), ".", n \ 6, "F51114", "No", " ", " ", " ", "Purchased", " ", "Primer")

maybe I should write it like this ?
VBA Code:
.Rows(lrNewRows) = Array(Cells(lr, "A"), ".", WorksheetFunction.RoundUp(n \ 6), "F51114", "No", " ", " ", " ", "Purchased", " ", "Primer")
 
Upvote 0
\ is the integer division operator which will truncate the result. So you need:

VBA Code:
WorksheetFunction.RoundUp(n / 6, 0)
 
Upvote 0
Solution

Forum statistics

Threads
1,223,888
Messages
6,175,213
Members
452,618
Latest member
Tam84

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