+ Reply to Thread
Results 1 to 22 of 22

Inserting decimals

  1. #1
    Registered User
    Join Date
    08-10-2015
    Location
    Washington
    MS-Off Ver
    Office 2016
    Posts
    5

    Inserting decimals

    Hello.

    I'm trying to either write or find a function that will automatically insert a decimal into different types of numbers. My spreadsheets contain three digit numbers and four digit numbers, but I want to auto place a decimal one space to the right of the first number on both of these.

    For example:

    256 | 1285
    255 | 1290
    254 | 1295
    259 | 1280

    I would like to be able to type those numbers but have it come out as:

    2.56 | 1.285
    2.55 | 1.290
    2.54 | 1.295
    2.59 | 1.280

    Short of having a fixed decimal at 3 and always having to add a zero to any three digit number and having one less decimal point in those boxes, I'm stumped as to how to accomplish this. I would like to only have to type the three numbers and the four numbers without manual placing decimals or adding zeros.
    Any help would be great.

    Thanks

  2. #2
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Inserting decimals

    Try this
    Formula in C1
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    Row\Col
    A
    B
    C
    D
    1
    256 1285 2.56 1.285
    2
    255 1290 2.55 1.29
    3
    254 1295 2.54 1.295
    4
    259 1280 2.59 1.28

  3. #3
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Inserting decimals

    I would recommend using an event macro to do this.

    Try posting a thread in the Excel Programming / VBA / Macros forum or contact a moderator and ask them to move this thread to that forum.
    Biff
    Microsoft MVP Excel
    Keep It Simple Stupid

    Let's Go Pens. We Want The Cup.

  4. #4
    Registered User
    Join Date
    08-10-2015
    Location
    Washington
    MS-Off Ver
    Office 2016
    Posts
    5

    Re: Inserting decimals

    I just posted this question in the macros thread. Thanks for the advice.

    And to quekbc, I don't think that formula is going to work because I still need the zeros at the end when I do type them.

  5. #5
    Registered User
    Join Date
    08-10-2015
    Location
    Washington
    MS-Off Ver
    Office 2016
    Posts
    5

    Re: Inserting decimals

    I just posted this question in the macros thread. Thanks for the advice.

    And to quekbc, I don't think that formula is going to work because I still need the zeros at the end when I do type them.

  6. #6
    Valued Forum Contributor ranman256's Avatar
    Join Date
    07-29-2012
    Location
    Kentucky
    MS-Off Ver
    Excel 2003
    Posts
    1,176

    Re: Inserting decimals

    press ALT-F11 to get to the macros
    in the left pane, dbl-click THISWORKBOOK
    in the right pane ,paste this code:

    Please Login or Register  to view this content.
    REMEMBER, macros CANNOT be saved in .xlsx files. Only .xls, or .xlsm

  7. #7
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Inserting decimals

    If you want to keep the numbers as numbers then this should work:
    Please Login or Register  to view this content.
    If you want to keep them as text so that all of the trailing zeros stay, then this should work:
    Please Login or Register  to view this content.
    Some people volunteer in soup kitchens or hospitals. I choose to make the world better by trying to help you with Excel. We're all learning.

    <---Click * Add Reputation for all helpful comments. It's like giving a smile.
    Forum Rules: How to mark your post [Solved] and have a happier, Excel enriched life.

  8. #8
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Inserting decimals

    Quote Originally Posted by trevorwlms View Post
    I just posted this question in the macros thread. Thanks for the advice.
    I see it and I'll keep an eye on it.

    Thanks for the feedback!

  9. #9
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Inserting decimals

    Just to make it easy to navigate. This thread is also here in the macro side:
    http://www.excelforum.com/excel-form...-decimals.html
    Last edited by alansidman; 08-11-2015 at 09:08 PM.

  10. #10
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Inserting decimals

    Just to make it easy to navigate, this thread is also posted here in the formulas side:
    http://www.excelforum.com/excel-prog...-decimals.html

    Moderator Edit: That thread has been closed and all discussion has been moved to this thread.
    Last edited by alansidman; 08-11-2015 at 09:08 PM.

  11. #11
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Inserting decimals

    Quote Originally Posted by Tony Valko View Post
    I would recommend using an event macro to do this.
    I still don't see why you would need a macro for this. Nevertheless, it is more likely due to my personal preference to avoid macros as much as possible.
    Quote Originally Posted by trevorwlms View Post
    And to quekbc, I don't think that formula is going to work because I still need the zeros at the end when I do type them.
    Formula to do what is required.
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  12. #12
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Inserting decimals

    Quote Originally Posted by quekbc View Post
    I still don't see why you would need a macro for this.
    It's the easiest solution based on the OP's requirement.

    And I say that being a non-programmer. However, I know enough about how VBA works to know when it's the best option.

    Type in 123 the event macro changes it to 1.230. Even though I don't know how to write the VBA to do that, I know it's fairly easy for someone that does know how to write the code.

  13. #13
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Inserting decimals

    Totally understand your view, but to reiterate. (And I say this as someone who knows a fair amount of programming) It is a personal view of mine that anything that can be done without VBA, should be done without VBA as there are quite a few "cons" to using VBA - especially for things as simple as this (e.g. lost of raw data, undo-tree removed, unintended consequences etc.). I find that, because EF is such a solution driven forum, that a lot of these "cons" aren't properly communicated to the person seeking the solution.

  14. #14
    Forum Expert Tony Valko's Avatar
    Join Date
    12-31-2011
    Location
    Pittsburgh
    MS-Off Ver
    2002, 2007:2013
    Posts
    18,890

    Re: Inserting decimals

    A good programmer can account for most, if not all, of the cons.

    Which leads us down another trail!

    Accounting for every possible condition, most of which are not a reality, is a waste of time and resources.

  15. #15
    Registered User
    Join Date
    08-10-2015
    Location
    Washington
    MS-Off Ver
    Office 2016
    Posts
    5

    Re: Inserting decimals

    ranman - I'm not sure how to make that macro keep the zeros at the end of my numbers.

    nigel - How do I write that formula to include multiple cells.

    This is a sample file I'm working with if that helps.
    1829JP - ABEWR 1502.xlsx

  16. #16
    Valued Forum Contributor quekbc's Avatar
    Join Date
    01-18-2010
    Location
    Sydney, Australia
    MS-Off Ver
    2010, 2013, 2016
    Posts
    1,149

    Re: Inserting decimals

    Strongly agree. But this doesn't happen often here. Solutions are "tailored" to solve a specific problem without any or minimal mention of potential consequences. Which is also understandable as (1) the solutions are provided voluntarily and no one is going to spend too much time on it to "dummy-proof" and (2) more often than not we do not have enough information to know what the potential consequences are.

    I shall stop now as I'm pretty sure some moderator is going to start making a fuss about this digression.

  17. #17
    Forum Moderator davesexcel's Avatar
    Join Date
    02-19-2006
    Location
    Regina
    MS-Off Ver
    MS 365
    Posts
    13,481

    Re: Inserting decimals

    @quekbc
    Can you explain to the OP how to use the formula?
    How is the formula supposed to format the existing cells?

    @trevorwlms
    What columns in your sample workbook do you require the custom formats?
    Last edited by davesexcel; 08-12-2015 at 05:13 AM.

  18. #18
    Valued Forum Contributor nigelbloomy's Avatar
    Join Date
    11-06-2013
    Location
    USA
    MS-Off Ver
    Excel 2010
    Posts
    1,011

    Re: Inserting decimals

    For my formulas in post #7 you would need to create a new column or sheet and then point the formula to the original data and drag the formula down as far as you need. This ends up creating a copy of your original data, but with the decimal added in. If you want something that will transform your original data, it will have to be a VBA solution.

  19. #19
    Forum Expert GeneralDisarray's Avatar
    Join Date
    09-15-2011
    Location
    Pittsburgh, PA, USA
    MS-Off Ver
    Windows Excel 2016
    Posts
    1,416

    Re: Inserting decimals

    I don't see where in that file you want to do this - but here's a way to go.

    1) PRE-FORMAT the cells for TEXT. That's the easiest way to keep a trailing (or leading) 0 value.

    2) The following will be your event macro code (2 subs for ease of use) - this code is placed in the worksheet's own code module (ask if you don't know what that means).

    About the code:

    The FOR EACH loop handles the off chance someone enters more than one value at a time (like if they copy and paste a range of data).

    Turning events on/off is just a good habit when working with a worksheet change event that itself causes a value change.

    ALSO! I highlighted in green where you need to tell excel where to do this.

    See attachment.


    Please Login or Register  to view this content.
    Attached Files Attached Files
    Last edited by GeneralDisarray; 08-12-2015 at 09:24 AM.
    Remember, saying thanks only takes a second or two. Click the star icon(*) below the post you liked, to give some Rep if you think an answer deserves it.

    Please,mark your thread [SOLVED] if you received your answer.

  20. #20
    Forum Expert
    Join Date
    01-23-2013
    Location
    USA
    MS-Off Ver
    Microsoft 365 aka Office 365
    Posts
    3,863

    Re: Inserting decimals

    Hi trevorwlms,

    See the attached file for a VBA solution to your question.

    The following code is in the ThisWorkbook module of your file:
    Please Login or Register  to view this content.
    Lewis

  21. #21
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Inserting decimals

    With the code below, adjust the column numbers to apply to the column(s) you need.

    Please Login or Register  to view this content.
    Acts 4:12
    Salvation is found in no one else, for there is no other name under heaven given to mankind by which we must be saved.

  22. #22
    Valued Forum Contributor natefarm's Avatar
    Join Date
    04-22-2010
    Location
    Wichita, Kansas
    MS-Off Ver
    2016
    Posts
    1,020

    Re: Inserting decimals

    Adjust the column number(s) in the code below to the column(s) you need. To keep trailing zeros, format the columns to two decimal places.

    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Replies: 2
    Last Post: 02-13-2015, 07:36 AM
  2. Replies: 0
    Last Post: 05-20-2014, 11:58 AM
  3. Decimals
    By Shradharani in forum Excel - New Users/Basics
    Replies: 2
    Last Post: 02-11-2013, 12:22 PM
  4. Replies: 6
    Last Post: 08-29-2010, 08:15 AM
  5. inserting cells into a hyperlink, inserting link via macro
    By jackmc in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-17-2007, 12:02 AM
  6. Decimals
    By Dohko in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-23-2007, 11:53 AM
  7. Inserting decimals
    By Randaddyz in forum Excel General
    Replies: 1
    Last Post: 03-08-2006, 03:55 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1