Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Excel 2010 Macro to Format Number to Remove the .0 at the End

Posted on 2016-07-19
4
Medium Priority
?
58 Views
Last Modified: 2016-07-19
We have Excel 2010 and Access 2010.

I exported some data from my Access database into an Excel spreadsheet named Example.xls.  In column A I have reference numbers, but some of the numbers are formatted wrong and I need to change them.

I need to remove the .0 from the end of any number.  In my attachment, I have highlighted the numbers which need to be changed with code.  For example the number 2014800136156.0 needs to be changed to 2014800136156.

Can anyone provide me with the code to change these numbers in column A automatically through vba macro.

Thanks in advance.
Example.xls
0
Comment
Question by:Senniger1
  • 2
4 Comments
 
LVL 53

Accepted Solution

by:
Rgonzo1971 earned 2000 total points
ID: 41719489
Hi,

Pls try
    Columns("A:A").Replace What:=".0", Replacement:="", LookAt:=xlPart, _
        SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False, _
        ReplaceFormat:=False

    Columns("A:A").NumberFormat = "0"

Open in new window

Regards
0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 41719499
Format the column as Text and then run this macro.

Sub RemoveZero()
Dim lngLastRow As Long
Dim lngRow As Long

lngLastRow = ActiveSheet.UsedRange.Rows.Count

For lngRow = 2 To lngLastRow
    If Right(Cells(lngRow, "A"), 2) = ".0" Then
        Cells(lngRow, "A") = Split(Cells(lngRow, "A"), ".")(0)
    End If
Next

End Sub

Open in new window

0
 
LVL 49

Expert Comment

by:Martin Liss
ID: 41719502
Use Rgonzo1971's code. It's better and faster than mine.
0
 

Author Closing Comment

by:Senniger1
ID: 41719568
Perfect!
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Windows Explorer lets you open cabinet (cab) files like any other folder. In VBA you can easily handle normal files and folders, but opening and indeed creating cabinet files takes a lot more - and that's you'll find here.
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.
Many functions in Excel can make decisions. The most simple of these is the IF function: it returns a value depending on whether a condition you describe is true or false. Once you get the hang of using the IF function, you will find it easier to us…

886 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question