How to round number with asterisks?

Wiley

New Member
Joined
Feb 28, 2012
Messages
4
Good morning,

I am curious whether it is possible to round a number with asterisks, but keeping those characters in the output? I have a regression tables with many decimals and significance levels ***, ** or * moreover some numbers are in parentheses. Would it be possible/exist a simple way to round the numbers to 2 or 3 decimals? I do not put my code - nothing works for me.

var1
0.969***
0.935***
0.934***
(0.0112)(0.00947)(0.00997)
var2
-0.0171**
-0.0138***-0.0138*

(0.00342)(0.00297)(0.00297)
dummy
0.0614***0.0615*
(0.0102)(0.0102)

<colgroup><col style="mso-width-source:userset;mso-width-alt:8777;width:180pt" width="240"> <col style="width:48pt" width="64" span="3"> </colgroup><tbody>
</tbody>

Kind regards,
Wiley
 

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
Code:
Function NumOnly(txt As String) As Long
Dim x
x = Split(Trim(txt), Chr(32))
NumOnly = Val(x(UBound(x)))
End Function
Sub roundnum()

For Each cell in ThisWorkbook.Sheets(1).Range("B1:C6")
cell.Value = Round(NumOnly(cell.Value), 2) & Right(cell.Value, LEN(cell.Value)-LEN(NumOnly(cell.Value))
Next cell
End Sub

Let me know if this works for you. Adjust the ranges to your preferences
 
Last edited:
Upvote 0
This code in my case stops at line "cell.Value =..." - in red
Thank you for quick reply and code
wiley
 
Upvote 0
Code:
[COLOR=#333333]Function NumOnly(txt As String) As Long[/COLOR]Dim x
x = Split(Trim(txt), Chr(32))
NumOnly = Val(x(UBound(x)))
End Function

Sub roundnum()

For Each cell in ThisWorkbook.Sheets(1).Range("B1:C6")
cell.Value = Round(NumOnly(cell.Value), 2) & Right(cell.Value, LEN(cell.Value)-LEN(NumOnly(cell.Value)))
Next cell 
[COLOR=#333333]End Sub[/COLOR]

forgot a parenthesis
 
Upvote 0
It shows "Compile error - variable required can't assign" in the same line highlited NumOnly:
cell.Value = Round(NumOnly(cell.Value), 2) & Right(cell.Value, Len(cell.Value) - Len(NumOnly(cell.Value)))

Thanks in any case
 
Upvote 0

Forum statistics

Threads
1,214,827
Messages
6,121,816
Members
449,049
Latest member
cybersurfer5000

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