+ Reply to Thread
Results 1 to 22 of 22

Round a Column of Numbers to a Specific List

  1. #1
    Registered User
    Join Date
    07-03-2011
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    31

    Round a Column of Numbers to a Specific List

    Hey All,

    In column E I have a list of numbers. I want to round all of them to the nearest number in the following list:

    400
    600
    800
    1000
    1200
    1400
    1600
    1800

    The closest I can find is this example, but I really am stumbling on where to start with it:
    http://excel.bigresource.com/Track/excel-bQaNOgRp/

    I dont need an error dialog box either for simplicity.

    If there's a way to do this with a regular macro set of actions great, but if not if you could help me do it via VBA i can work that too.

    I will most definately give good ratings to ANYONE that may be able to help me.

    Thanks!

    - Brandon

  2. #2
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Round a Column of Numbers to a Specific List

    Could you use the MROUND function? It looks like your list is incremented by 200. So if your data is in column A it would be:
    Please Login or Register  to view this content.
    and if you need it to never be below 400 you could use:
    Please Login or Register  to view this content.
    -Greg If this is helpful, pls click Star icon in lower left corner

  3. #3
    Registered User
    Join Date
    07-03-2011
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Round a Column of Numbers to a Specific List

    Quote Originally Posted by gjlindn View Post
    Could you use the MROUND function? It looks like your list is incremented by 200. So if your data is in column A it would be:
    Please Login or Register  to view this content.
    and if you need it to never be below 400 you could use:
    Please Login or Register  to view this content.
    Is a2 only going to round column a row 2 or does that do the entire column? I guess ill go try this (Im on my android right now). Ill get back to you soon and give you some positive feedback if it works!

  4. #4
    Forum Guru
    Join Date
    05-24-2011
    Location
    India
    MS-Off Ver
    365
    Posts
    2,243

    Re: Round a Column of Numbers to a Specific List

    Or,

    Consider A:A is the list of numbers, E:E is the actual numbers, So try this.

    =SMALL(A:A,MIN(COUNT(A:A),COUNTIF(A:A,"<="&E1)+1))
    Regards,
    Haseeb Avarakkan

    __________________________________
    "Feedback is the breakfast of champions"

  5. #5
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Round a Column of Numbers to a Specific List

    Just for kicks I also created this UDF which will also do what you're looking for but is not limited to a static increment.
    Please Login or Register  to view this content.
    If your list is in $F$2:$F$9 and your target is in A2 then:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    07-03-2011
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Round a Column of Numbers to a Specific List

    Let me try to explain a little better:

    I have a list of numbers down Column E. I want them all calculated to overwrite into Column E. Increments of 200. I need a script that will do the entire column.

    If someone can get a little more exact on how to help i'd appreciate it. I have given good reputation to everryone that has responded.
    Last edited by BCossette; 08-07-2011 at 11:29 PM.

  7. #7
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Round a Column of Numbers to a Specific List

    @Haseeb A
    =SMALL(A:A,MIN(COUNT(A:A),COUNTIF(A:A,"<="&E1)+1))
    This is very nice, but appears to be always round up.


    @BCossette
    Is a2 only going to round column a row 2 or does that do the entire column?
    MROUND is a formula you'd put into another cell...so it doesn't change the value of A2. You'd have to copy the formula down in order to apply to other cells. The same is true for the UDF i provided. If you want a macro to replace values I could easily modify the UDF to be a sub routine that does that. Thanks!

  8. #8
    Registered User
    Join Date
    07-03-2011
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Round a Column of Numbers to a Specific List

    Quote Originally Posted by gjlindn View Post
    Could you use the MROUND function? It looks like your list is incremented by 200. So if your data is in column A it would be:
    Please Login or Register  to view this content.
    and if you need it to never be below 400 you could use:
    Please Login or Register  to view this content.
    Im getting a circular reference error and it automatically makes the number in the column 0. Im using the following code in just one cell (E7) to try and get this to work:

    =MROUND(E7,200)

  9. #9
    Registered User
    Join Date
    07-03-2011
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Round a Column of Numbers to a Specific List

    Quote Originally Posted by gjlindn View Post
    @Haseeb A This is very nice, but appears to be always round up.


    @BCossette MROUND is a formula you'd put into another cell...so it doesn't change the value of A2. You'd have to copy the formula down in order to apply to other cells. The same is true for the UDF i provided. If you want a macro to replace values I could easily modify the UDF to be a sub routine that does that. Thanks!
    Could you alter the UDF for me? Also ive never used a UDF, i've only done basic VBA code. I'm not sure where to integrate the two separate codes you have given me.

    Thanks again guys.

  10. #10
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Round a Column of Numbers to a Specific List

    A UDF is just a function put into a standard Module. Once you've done that, you can use the function just like you would any a standard Excel function (by typing it into a worksheet cell). You can input the following code to a standard or worksheet module and then call the RoundMe routine from the Macros button on the Devoloper tab. Remember to change the ranges in the code to your own.
    Please Login or Register  to view this content.

  11. #11
    Registered User
    Join Date
    07-03-2011
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Round a Column of Numbers to a Specific List

    Im sorry if im just being a nitpick at this point:

    How do I alter the code so that it does the entire column? There's always going to be a different amount of column values with each spreadsheet im doing this to.

    Can you integrate the desired numbers to be specified into the subroutine? It would look much better than having a random string of numbers laying around on the spreadsheet.

    Edit: I got this fully functional minus the above alterations needed. Appreciate all the help thus far guys.
    Last edited by BCossette; 08-08-2011 at 12:40 AM.

  12. #12
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Round a Column of Numbers to a Specific List

    Sure...here you go:
    Please Login or Register  to view this content.
    You can change/add numbers in the array right in the code now.
    Last edited by gjlindn; 08-08-2011 at 12:47 AM.

  13. #13
    Registered User
    Join Date
    07-03-2011
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Round a Column of Numbers to a Specific List

    Quote Originally Posted by gjlindn View Post
    Sure...here you go:
    Please Login or Register  to view this content.
    You can change/add numbers in the array right in the code now.
    PERFECT ! ! !

    I have a few more questions related to my little program im making, but i'll mark this resolved and make new topics. Thanks again everyone.

  14. #14
    Registered User
    Join Date
    07-03-2011
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Round a Column of Numbers to a Specific List

    gjlindn,

    Can you look at my program and tell me what i'm doing wrong? It worked at first, but now i'm getting a Run Time Error 13: Type Mismatch. I've tried everything and can't figure out what i'm doing wrong.

    The file is too big to upload here, so download it from my web server:

    http://www.1badz71tahoe.webs.com/427VEFixerv121.xlsm

    THANKS!

    - Brandon

  15. #15
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Round a Column of Numbers to a Specific List

    Hi Brandon,

    Change this
    Please Login or Register  to view this content.
    to this:
    Please Login or Register  to view this content.
    The "2" represented the first row of data you want to change. In your workbook it starts in row 7. Thanks!

  16. #16
    Registered User
    Join Date
    07-03-2011
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Round a Column of Numbers to a Specific List

    If you still have my project . . .

    I'm getting an erroneous couple 400's in E3 and E4 once doing the macro by button click. Is there anyway to stop these from coming up without hiding them? Efficient and Clean Code for the Win! :-)
    Last edited by BCossette; 08-08-2011 at 01:49 PM.

  17. #17
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Round a Column of Numbers to a Specific List

    Sorry...which tab? Would this be easier if when you click the button it prompts you to highlight a range to apply the rounding to?

  18. #18
    Registered User
    Join Date
    07-03-2011
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Round a Column of Numbers to a Specific List

    Quote Originally Posted by gjlindn View Post
    Sorry...which tab? Would this be easier if when you click the button it prompts you to highlight a range to apply the rounding to?
    Hey,

    Near Idle Tab, When you click Round RPM. Next Step will be to apply this same concept to Off Idle Sheet.

    I don't think making a selection would help, it would take longer to complete it? I just want that entire column calculated regardless of the number of "Datalogs" (reading of sensors on engine, by row).

    Also, can you look at http://www.excelforum.com/excel-programming/787304-filtering-data-keeping-rows-of-information-intact.html ?

    I have attempted to code one via a regular macro (I'd have to remember to myself that I have a datalog limit, which would stink), and I tried the other one with VBA. The VBA was an example i found online and cant get it to suit my needs.

    THANKS!!!!!!!!!!!!

  19. #19
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Round a Column of Numbers to a Specific List

    Try updating your macro to this:
    Please Login or Register  to view this content.
    It has a couple of prompts, but if your data moves or is in different columns it will be easy to adjust this way.

    As for your other post at http://www.excelforum.com/excel-prog...on-intact.html I have the same issue as BigBas...prehistoric version of Excel at work...so will have to wait until tonight. I'll lay off that one since BigBas is on it. Best of luck!

  20. #20
    Registered User
    Join Date
    07-03-2011
    Location
    Maine
    MS-Off Ver
    Excel 2010
    Posts
    31

    Re: Round a Column of Numbers to a Specific List

    Thanks gjlindn!

    My last question, and i'm taking a break until BigBas can help me with that other issue tonight:

    Same Sheet, Button "Simplify Near Idle". I have a basic macro there and it can stay that way as far as i'm concerned, but how do I Delete D E and F without Dragging down the entire column? Is there a way that it'll automatically just delete that entire column? I know there is a way, but I guess i'm just getting too complex for myself.

    If i am not following the guidelines of this forum, you don't HAVE to do it for me, you can refer me to some references, but I won't complain if you guys just want to do the sections for me as far as ease for yourselves.

  21. #21
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Round a Column of Numbers to a Specific List

    how do I Delete D E and F without Dragging down the entire column?
    Deleting can mean at least two things to people. See these examples:
    Please Login or Register  to view this content.

  22. #22
    Valued Forum Contributor gjlindn's Avatar
    Join Date
    08-01-2011
    Location
    Dodgeville, WI
    MS-Off Ver
    Excel 2003, 2007, 2010, 2013
    Posts
    369

    Re: Round a Column of Numbers to a Specific List

    I'm thinking I should probably mention that if something seems like it should be simple, it very likely is. An easy way to learn simple VBA is to use the Excel Macro Recorder. It will usually create lots of extra, unnecessary lines of code, but it is pretty easy to clean up and will help you with the more simple Excel functions. Happy coding!

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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