Excel VBA Course
Excel VBA Course - From Beginner to Expert

200+ Video Lessons
50+ Hours of Video
200+ Excel Guides

Become a master of VBA and Macros in Excel and learn how to automate all of your tasks in Excel with this online course. (No VBA experience required.)

View Course

Remove the data from Decimal

0

Vba will be placed in a seperate file

my file name sample1.xlsx I have a column D which contains numbers with decimals so i want to remove the data  from decimals by vba

example 

column D

data

10

10.2352

25.02547

what i want is to remove the data from decimal means

10.2352 to 10

25.02547 to 25

like this 

all files are located in same place vba will be placed in a macro.xlsm

and macro.xlsm  and sample1.xlsx are in same place

sample1.xlsx is not opened so we have to open the same by vba

and after the process completed  save and close the file

Answer
Discuss

Answers

0
Selected Answer

Consider not to change your data. In most cases it is preferrable to keep the original cell value at 10.2352 but display 10 in the cell. Even if you wish to use the integer 10 in onward calculations you could use ROUND(10.2352, 0) instead of a simple reference and still maintain your original data unchanged.

Change the displayed value using cell formatting: Format Cells > Number > Number and set Decimal places to 0. Note that this setting would automatically round the display 5/4, meaning 10.5 will be displayed as 11, 10.49 as 10. The ROUND function, either on the worksheet or in VBA, would do the same.

If you wish to apply this format using VBA you might use this code.

    With Worksheets("Sheet1")
        .Range(.Cells(2, "D"), .Cells(.Rows.Count, "D").End(xlUp)).NumberFormat = "0"
    End With

Change the sheet name to the name to match the name of the worksheet on which you wish to set the number format. use the format string "#,##0" if you need a thousands separator.

Discuss

Discussion

Thnx Variatus Mam For ur great support and ur Great Guidance
Have a Great Day
avinash (rep: 10) Aug 26, '19 at 6:55 am
Add to Discussion


Answer the Question

You must create an account to use the forum. Create an Account or Login