Solved

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

Posted on 2016-07-19
4
48 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 51

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 47

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 47

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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
Graphs within dashboards are meant to be dynamic, representing data from a period of time that will change each time the dashboard is updated with new data. Rather than update each graph to point to a different set within a static set of data, t…

738 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