Can someone tell me how to leave the number with only 4 decimal places?

KhallP

Board Regular
Joined
Mar 30, 2021
Messages
157
Office Version
  1. 2016
Platform
  1. Windows
The "error":

provas.JPG



The code:
Code:
    Dim oPL As Double, o709 As Double, o710 As Double, o713 As Double
    Application.ScreenUpdating = False
    Sheets("Calculation_Sheet").Visible = True

    ActiveWorkbook.Sheets("calculation_sheet").Activate

Note: P666, P709, P710 and P713 are global variables
Code:
    Range("B18").Select
    ActiveCell = A_90
    Range("B26").Select
    ActiveCell = A0
    Range("B33").Select
    ActiveCell = A90
      
    Range("I6").Select
    oPL = ActiveCell.Value
    Range("I7").Select
    o709 = ActiveCell.Value
    Range("I8").Select
    o710 = ActiveCell.Value
    Range("I9").Select
    o713 = ActiveCell.Value
  
    oPL = Format(oPL, "0.####")
    o709 = Format(o709, "0.####")
    o710 = Format(o710, "0.####")
    o713 = Format(o713, "0.####")
  
    Range("J6").Select
    P666 = ActiveCell.Value
    Range("J7").Select
    P709 = ActiveCell.Value
    Range("J8").Select
    P710 = ActiveCell.Value
    Range("J9").Select
    P713 = ActiveCell.Value
  
    P666 = Format(P666, "0.####")
    P709 = Format(P709, "0.####")
    P710 = Format(P710, "0.####")
    P713 = Format(P713, "0.####")
  
    out_666.Value = P666
    out_709.Value = P709
    out_710.Value = P710
    out_713.Value = P713
 
Last edited by a moderator:

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
At the image, I see your numbers digits is more than 4 and didn't see decimal digits.
if you want to limit decimal digits to 4 try this:
Change format to this type:
Example:
VBA Code:
oPL = Format(oPL, "#,##0.0000")

if you want to See only decimal digits without numbers before Digit Try this:
VBA Code:
oPL = Format(oPL - Int(oPL/1), "#,##0.0000")
 
Last edited:
Upvote 0
or with your method
VBA Code:
oPL = Format(oPL - Int(oPL/1), "0.####")
 
Upvote 0
At the image, I see your numbers digits is more than 4 and didn't see decimal digits.
if you want to limit decimal digits to 4 try this:
Change format to this type:
Example:
VBA Code:
oPL = Format(oPL, "#,##0.0000")

if you want to See only decimal digits without numbers before Digit Try this:
VBA Code:
oPL = Format(oPL - Int(oPL/1), "#,##0.0000")
the error remains :(


error.JPG
 
Upvote 0
Are you change all format function at code to this type? or only oPL?
All should be change not only OPL
VBA Code:
oPL = Format(oPL - Int(oPL/1), "#,##0.0000")
Then Should be:
VBA Code:
oPL = Format(oPL - Int(oPL/1), "#,##0.0000")
o709 = Format(o709 - Int(o709/1), "#,##0.0000")
o710 = Format(o710 - Int(o710/1), "#,##0.0000")
o713 = Format(o713 - Int(o713/1), "#,##0.0000")

Range("J6").Select
P666 = ActiveCell.Value
Range("J7").Select
P709 = ActiveCell.Value
Range("J8").Select
P710 = ActiveCell.Value
Range("J9").Select
P713 = ActiveCell.Value

P666 = Format(P666 - Int(P666/1), "#,##0.0000")
P709 = Format(P709 - Int(P709/1), "#,##0.0000")
P710 = Format(P710 - Int(P710/1), "#,##0.0000")
P713 = Format(P713 - Int(P713/1), "#,##0.0000")
 
Upvote 0
Int(o709/1), "#,##0.0000") o710 = Format(o710 - Int(o710/1), "#,##0.0000")
It didn't work, going back to the initial code, to be more specific, the comma has to be right there between "3" and "1", can you help me?


test.JPG



Should work because the code limits the value to 4 decimal places...

oPL = Format(oPL, "0.####")
o709 = Format(o709, "0.####")
o710 = Format(o710, "0.####")
o713 = Format(o713, "0.####")

Range("J6").Select
P666 = ActiveCell.Value
Range("J7").Select
P709 = ActiveCell.Value
Range("J8").Select
P710 = ActiveCell.Value
Range("J9").Select
P713 = ActiveCell.Value

P666 = Format(P666, "000.####")
P709 = Format(P709, "0.####")
P710 = Format(P710, "0.####")
P713 = Format(P713, "0.####")
 
Upvote 0
Are you try this method for all Format Functions
VBA Code:
oPL = Format(oPL - Int(oPL/1), "0.####")
 
Upvote 0

Hi,​
As I read some bad logic in yours posts so you must give us a clear example of the source value and what is your expected result ?​
 
Upvote 0
Hi,​
As I read some bad logic in yours posts so you must give us a clear example of the source value and what is your expected result ?​
I can´t sry, im working at Embraer many things are private
 
Upvote 0

Forum statistics

Threads
1,214,521
Messages
6,120,018
Members
448,937
Latest member
BeerMan23

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