convert number stored as text to number without rounding the numbers

star_saty

New Member
Joined
Jul 6, 2014
Messages
2
Hi All,

I am looking for a VBA code for the below issue, Please help.

I am stuck where i have to convert the number which are stored as text and i have to convert them in number format and it should not round up the numbers.
Below is the sample data for your reference. once data gets convert to number it should look like as it is but it should be converted into number format.

In Excel When number are in text format they are aligned to Left but once it get converted to number format they are align to Right

See below screencap of the same.

Text Format Data
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Column1[/TD]
[TD]Column2[/TD]
[TD]Column3[/TD]
[/TR]
[TR]
[TD]1.323551[/TD]
[TD]90.92[/TD]
[TD]6604.38[/TD]
[/TR]
[TR]
[TD]0.570486[/TD]
[TD]3.17[/TD]
[TD]2505.14[/TD]
[/TR]
[TR]
[TD]0.894552[/TD]
[TD]7.25[/TD]
[TD]13438.28[/TD]
[/TR]
</tbody>[/TABLE]


After converting above to number format it should look like below
[TABLE="class: grid, width: 500, align: left"]
<tbody>[TR]
[TD]Column1[/TD]
[TD]Column2[/TD]
[TD]Column3[/TD]
[/TR]
[TR]
[TD="align: right"]1.323551[/TD]
[TD="align: right"]90.92[/TD]
[TD="align: right"]6604.38[/TD]
[/TR]
[TR]
[TD="align: right"]0.570486[/TD]
[TD="align: right"]3.17[/TD]
[TD="align: right"]2505.14[/TD]
[/TR]
[TR]
[TD="align: right"]0.894552[/TD]
[TD="align: right"]7.25[/TD]
[TD="align: right"]13438.28[/TD]
[/TR]
</tbody>[/TABLE]



Your help will be highly appreciated.
Thanks in advance
 

Excel Facts

What is =ROMAN(40) in Excel?
The Roman numeral for 40 is XL. Bill "MrExcel" Jelen's 40th book was called MrExcel XL.
Welcome to MrExcel.

Have you tried Data|Text To Columns|Finish? The macro recorder will give you the VBA code.
 
Upvote 0
Hi Andrew,

I am using below code to do the task but it roundup the number. Below code roundup the number to 1 digit.

sub report()
Range("A2:A4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
Call Number
End sub

Sub number()
Range("A2:A4").Select
Range(Selection, Selection.End(xlDown)).Select
Range(Selection, Selection.End(xlDown)).Select
ActiveSheet.Select
With Selection
Selection.NumberFormat = "0"
.Value = .Value
End With
End Sub
 
Upvote 0
The code doesn't do any rounding. But this line formats the numbers with zero decimal places:

Code:
Selection.NumberFormat = "0"

Try using the General number format.
 
Upvote 0

Forum statistics

Threads
1,223,228
Messages
6,170,871
Members
452,363
Latest member
merico17

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