Limiting a VBA variable's significant figures

ExcelVBANOOB

New Member
Joined
May 7, 2014
Messages
7
I'm working with a code currently, and the calculations are coming out with WAY more sig figs than I need. Is there any way to limit the sig figs of a specific "variable" in VBA? For instance, r1 is the first root from the quadratic equation for a given polynomial, based on coefficients a, b and c. If a=b=c=1, r1 (imaginary)=0.3660254i. That comes out in a message box, so the calculation isn't taking place in a cell, where I can just "activecell.numberformat = "0.000"." Would I need to assign the value to a cell, format the cell, and then take the output, or is there another way?
 

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Using the format function would do it. Like this:

Code:
MsgBox (Format([COLOR="#0000FF"][B]YourValue[/B][/COLOR], "0.000"))


Change YourValue to your actual value.
 
Upvote 0

Forum statistics

Threads
1,223,268
Messages
6,171,100
Members
452,379
Latest member
IainTru

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