Rounding Up Numbers using VB

Mark.B

Board Regular
Joined
Jun 14, 2004
Messages
134
Hi there.

Within a VB procedure i have a very simple calculation i.e. Number 1 divided by Number 2 = Answer.
The results returned always have multiple decimal places i.e. 98.827876.

I would like to pass / insert this value into a Textbox which has been embedded into a Worksheet, but I need it to appear as a % with either 1 or no decimal places.

I've added the % symbol in the simplest that I know i.e. TextboxText = Answer & "%" but the end result shows as 98.827876% (I need to lose all of the decimal places)

Is it possible to Round Up the "Answer" to the calculation being performed inside the procedure within VB ?

or

Can I limit the value which is being passed to the embedded textbox so that the end result is simply 98.8% or 99% ?

Hope this makes sense.

Any help would be greatly appreciated.
 

Some videos you may like

Excel Facts

Bring active cell back into view
Start at A1 and select to A9999 while writing a formula, you can't see A1 anymore. Press Ctrl+Backspace to bring active cell into view.

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,253
Office Version
  1. 365
Platform
  1. Windows
How about
VBA Code:
Me.TextBox3 = Application.RoundUp(answer, 1) & "%"
 
Solution

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
55,253
Office Version
  1. 365
Platform
  1. Windows
You're welcome & thanks for the feedback.
 

Watch MrExcel Video

Forum statistics

Threads
1,126,986
Messages
5,621,992
Members
415,873
Latest member
fuulhouse

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
Top