Round by 2 decimals

Romano_odK

Active Member
Joined
Jun 4, 2020
Messages
379
Office Version
  1. 365
Platform
  1. Windows
Good morning,

In VBA I have the following sub (see below). I need to round column C by 2 decimals at the end of the sub. Column C is in a table. Is there a way to do this?

Thank you in advance,

Private Sub KopieerNaarVerkoopprijs_Click()
With Sheets("OPXML").ListObjects("Table_Query_from_A100")
.ListColumns(3).DataBodyRange.Value = .ListColumns(4).DataBodyRange.Value
End With
Range("E9:E15000").ClearContents
Range("F9:F15000").ClearContents
Range("G9:G15000").ClearContents
Range("H9:H15000").ClearContents
Range("E7").ClearContents
Range("E7").Value = 0
Range("C9").Select
End Sub
 

Excel Facts

Which came first: VisiCalc or Lotus 1-2-3?
Dan Bricklin and Bob Frankston debuted VisiCalc in 1979 as a Visible Calculator. Lotus 1-2-3 debuted in the early 1980's, from Mitch Kapor.
Hi

Does the below work

Was there a reason not to clear all the columns in 1 go?

VBA Code:
Private Sub KopieerNaarVerkoopprijs_Click()
With Sheets("OPXML").ListObjects("Table_Query_from_A100")
.ListColumns(3).DataBodyRange.Value = .ListColumns(4).DataBodyRange.Value
End With
   Range("E9:H15000").ClearContents
   Range("E7").Value = 0
Columns("C:C").NumberFormat = "0.00"
End Sub
 
Upvote 0
May be:
VBA Code:
Private Sub KopieerNaarVerkoopprijs_Click()
With Sheets("OPXML").ListObjects("Table_Query_from_A100")
.ListColumns(3).DataBodyRange.Value = Evaluate("=ROUND(Table_Query_from_A100[Column4],2)")
End With
Range("E9:H15000").ClearContents
Range("E7").Value = 0
Range("C9").Select
End Sub
 
Upvote 0
May be:
VBA Code:
Private Sub KopieerNaarVerkoopprijs_Click()
With Sheets("OPXML").ListObjects("Table_Query_from_A100")
.ListColumns(3).DataBodyRange.Value = Evaluate("=ROUND(Table_Query_from_A100[Column4],2)")
End With
Range("E9:H15000").ClearContents
Range("E7").Value = 0
Range("C9").Select
End Sub
Good morning,

Tried it but no succes, got a #Value! error in column C.
 
Upvote 0
Hi

Does the below work

Was there a reason not to clear all the columns in 1 go?

VBA Code:
Private Sub KopieerNaarVerkoopprijs_Click()
With Sheets("OPXML").ListObjects("Table_Query_from_A100")
.ListColumns(3).DataBodyRange.Value = .ListColumns(4).DataBodyRange.Value
End With
   Range("E9:H15000").ClearContents
   Range("E7").Value = 0
Columns("C:C").NumberFormat = "0.00"
End Sub
Tried it but no succes unfortunately.
 
Upvote 0
Good morning,

Tried it but no succes, got a #Value! error in column C.
If it works for you to do so, if you replace [Column4] using your real Column Name for the 4th column (enclosed in the square brackets) in the following line:
VBA Code:
        .ListColumns(3).DataBodyRange.Value = Evaluate("=ROUND(Table_Query_from_A100[Column4],2)")
I expect that @bebo021999 's solution might work for you.
 
Upvote 0
Good morning,

In VBA I have the following sub (see below). I need to round column C by 2 decimals at the end of the sub. Column C is in a table. Is there a way to do this?

Thank you in advance,

Private Sub KopieerNaarVerkoopprijs_Click()
With Sheets("OPXML").ListObjects("Table_Query_from_A100")
.ListColumns(3).DataBodyRange.Value = .ListColumns(4).DataBodyRange.Value
End With
Range("E9:E15000").ClearContents
Range("F9:F15000").ClearContents
Range("G9:G15000").ClearContents
Range("H9:H15000").ClearContents
Range("E7").ClearContents
Range("E7").Value = 0
Range("C9").Select
End Sub
Instead of changing this VBA I could also be hapy if ROUND could be added to this line.. if that works my problem would be solved also.



=IFERROR((IFS(H9>0;K9/(1-H9);G9>0;K9*G9+K9;F9>0;F9;E9>0;E9*AH9+AH9;$D$7>0;$D$7*AH9+AH9;$D$7>0;$D$7*AI9+AI9;$D$7>0;$D$7*AJ9+AJ9));AH9)
 
Upvote 0
If the formula always produces a numeric result then just wrap it in a round function.

Excel Formula:
=ROUND(IFERROR((IFS(H9>0;K9/(1-H9);G9>0;K9*G9+K9;F9>0;F9;E9>0;E9*AH9+AH9;$D$7>0;$D$7*AH9+AH9;$D$7>0;$D$7*AI9+AI9;$D$7>0;$D$7*AJ9+AJ9));AH9),2)
 
Upvote 0

Forum statistics

Threads
1,214,834
Messages
6,121,876
Members
449,056
Latest member
ruhulaminappu

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