Solved

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

Posted on 2016-07-19
4
40 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 48

Accepted Solution

by:
Rgonzo1971 earned 500 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 45

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 45

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This Micro Tutorial demonstrates how to create Excel charts: column, area, line, bar, and scatter charts. Formatting tips are provided as well.
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now