Removing Decimal Points In An Array- VBA HELP

milwphil

Board Regular
Joined
Aug 1, 2010
Messages
120
Collective Mr. Excel Brain,

I'm trying to come up with code to remove decimals points in a couple columns of a spreadsheet.

The spreadsheet that I inherited uses dataArray's... What I'd like to do is somehow remove the decimal points in a couple of columns (M and N).

I thought using a similar method to the below method would work (after the number has been rounded), but I'm not having much luck.
Code:
[COLOR=red][SIZE=3][FONT=Calibri]If Val(dataArray(tmpRow, tmpCol)) <> Val(Round(Val(dataArray(tmpRow, tmpCol)), 0)) Then<?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /><o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=red][SIZE=3][FONT=Calibri]                  cellWarning = True<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=red][SIZE=3][FONT=Calibri]                  Call updateWarnText(tmpRow, tmpCol, "The location # was changed from " & dataArray(tmpRow, tmpCol) & " to " & Round(Val(dataArray(tmpRow, tmpCol)), 0))<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=red][SIZE=3][FONT=Calibri]                  dataSheet.Cells(tmpRow, tmpCol).Value = Val(Round(Val(dataArray(tmpRow, tmpCol)), 0))<o:p></o:p>[/FONT][/SIZE][/COLOR]
[COLOR=red][SIZE=3][FONT=Calibri]              End If[/FONT][/SIZE][/COLOR]<o:p></o:p>

Any suggestions?

YOUR HELP IS GREATLY APPRECIATED!
 

Excel Facts

When they said...
When they said you are going to "Excel at life", they meant you "will be doing Excel your whole life".
Why not just use Replace?

Code:
Sub test()
Range("M:N").Replace ".", ""
End Sub
 
Upvote 0
I'm unclear what "remove decimals points" means. 123.45 -> 123? 678.9 -> 6789?

Can you give us some typical values and what you want them turned into?
 
Upvote 0
Thanks for the responses!

For example:

123.45 should be rounded to 123

However, when people cut and paste data from a table that's formatted as a number, into my spreadsheet it maintains the decimal points after rounding.

Subsequently, 123.45 is rounded to 123.00

I just want to remove the decimal places.

Is there any way I could add to my code after the rounding is completed to just remove the decimal places?

Thanks,
Phil
 
Upvote 0
Change the number format of the area as you wish.
 
Upvote 0
GlennUK,

I'm not sure I understand your response. Where would I make the change.

The formats that are being cut and pasted are being transferred to my spreadsheet. Is there anyway to keep the format of my spreadsheet (in the code that I'm using to Round/warn the user of the rounding and also make the formatting seemless to the user)?

I apologize I'm still somewhat of a novice (it may very well be that the answer is so simple I'm making it difficult).

Thanks,
Phil
 
Upvote 0
Code:
dataSheet.Cells(tmpRow, tmpCol).NumberFormat = "General"
 
Upvote 0

Forum statistics

Threads
1,224,527
Messages
6,179,357
Members
452,907
Latest member
Roland Deschain

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