Add rounding to 2 dm to VBA code

nihad

New Member
Joined
Feb 24, 2021
Messages
40
Office Version
  1. 365
Platform
  1. Windows
Hi all

I have this following code, I want to add rounding to 2 decimals to this code:

VBA Code:
'Net amount
Sheet1.Cells(rr, 8) = sh.Cells(k, 12)

'VAT amount
Sheet1.Cells(rr, 10) = sh.Cells(k, 9)

full code is below:


VBA Code:
Sub EXPENSE_JOURNAL_FOLDER()


Application.DisplayAlerts = False

d = GetFolderName()
d = d & "\"

Count = 0


Application.DisplayAlerts = False

sfile = Dir(d & "*.xls*")

rr = Sheet1.Cells(Sheet1.Rows.Count, 1).End(xlUp).Row + 2

Do While sfile <> ""
       
Set wb = Workbooks.Open(d & sfile)
'Set wb = ActiveWorkbook
Set sh = wb.Sheets(1)


n1 = 10
For n = 10 To 200
If sh.Cells(n, 1) = "TOTAL CLAIM" Then
n2 = n - 3
Exit For
End If
Next n



For n = n2 To n2 + 200
If sh.Cells(n, 1) = "Date" Then
m1 = n + 1
Exit For
End If
Next n

For n = m1 To m1 + 200
If sh.Cells(n, 1) = "TOTAL MILEAGE" Then
m2 = n - 3
Exit For
End If
Next n

nm = sh.Range("B3")
fn = Split(nm, " ")
fn1 = Left(fn(0), 1)
fn2 = Left(fn(1), 1)
fname = "EXP" & fn1 & fn2 & Format(Sheet1.Range("G2"), "ddmmyy")



For k = n1 To n2
If sh.Cells(k, 1) <> "" Then

'PI
Sheet1.Cells(rr, 1) = "PI"
Sheet1.Cells(rr, 2) = sh.Range("O4")
Sheet1.Cells(rr, 3) = sh.Cells(k, 15)
Sheet1.Cells(rr, 4) = sh.Cells(k, 16)
Sheet1.Cells(rr, 5) = Format(Sheet1.Range("G2"), "dd/mm/yyyy")

Sheet1.Cells(rr, 6) = fname
Sheet1.Cells(rr, 7) = sh.Cells(k, 3)

'Net amount
Sheet1.Cells(rr, 8) = sh.Cells(k, 10)

'VAT amount
Sheet1.Cells(rr, 10) = sh.Cells(k, 9)

Sheet1.Cells(rr, 9) = "T0"

If Sheet1.Cells(rr, 10) > 0 Then
Sheet1.Cells(rr, 9) = "T1"
End If



Sheet1.Cells(rr, 11) = 1
Sheet1.Cells(rr, 12) = "ISEXPORT:" & Format(Sheet1.Range("G2"), "dd/mm/yyyy")


rr = rr + 1
End If
Next k



'Mileage Form


For k = m1 To m2
If sh.Cells(k, 1) <> "" Then

'PI
Sheet1.Cells(rr, 1) = "PI"
Sheet1.Cells(rr, 2) = sh.Range("O4")
Sheet1.Cells(rr, 3) = sh.Cells(k, 15)
Sheet1.Cells(rr, 4) = sh.Cells(k, 16)
Sheet1.Cells(rr, 5) = Format(Sheet1.Range("G2"), "dd/mm/yyyy")

Sheet1.Cells(rr, 6) = fname
Sheet1.Cells(rr, 7) = sh.Cells(k, 3) & " to " & sh.Cells(k, 4)

'Net amount
Sheet1.Cells(rr, 8) = sh.Cells(k, 12)

'VAT amount
Sheet1.Cells(rr, 10) = sh.Cells(k, 9)

Sheet1.Cells(rr, 9) = "T0"

If Sheet1.Cells(rr, 10) > 0 Then
Sheet1.Cells(rr, 9) = "T1"
End If



Sheet1.Cells(rr, 11) = 1
Sheet1.Cells(rr, 12) = "ISEXPORT:" & Format(Sheet1.Range("G2"), "dd/mm/yyyy")


rr = rr + 1
End If
Next k




'rr = rr + 1
wb.Close
sfile = Dir
Count = Count + 1
Loop



Application.DisplayAlerts = True

MsgBox "Done . . .  " & Count & " Files are Processed."



End Sub
Public Function GetFolderName(Optional OpenAt As String) As String
Dim lCount As Long

GetFolderName = vbNullString

With Application.FileDialog(msoFileDialogFolderPicker)
    .InitialFileName = OpenAt
    .Show
    For lCount = 1 To .SelectedItems.Count
        GetFolderName = .SelectedItems(lCount)
    Next lCount
End With
End Function
 

Excel Facts

Does the VLOOKUP table have to be sorted?
No! when you are using an exact match, the VLOOKUP table can be in any order. Best-selling items at the top is actually the best.
VBA Code:
   Sheet1.Cells(rr, 8) = Round(sh.Cells(k, 12), 2)
   Sheet1.Cells(rr, 10) = Round(sh.Cells(k, 9), 2)
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,340
Members
452,638
Latest member
Oluwabukunmi

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