+ Reply to Thread
Results 1 to 14 of 14

Macro inputs values between two numbers and sort accordingly

  1. #1
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Macro inputs values between two numbers and sort accordingly

    I need a macro that inputs the values between two numbers (always in range between 1-52) and inputs them accordingly in table in corresponding columns.

    I've tried with bellow one, but it doesn't sort the numbers:
    Please Login or Register  to view this content.
    Please see attached file.
    Attached Files Attached Files
    Last edited by Tona; 12-16-2015 at 07:39 AM.

  2. #2
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro inputs values between two numbers and sort accordingly

    Perhaps a macro like this?

    Please Login or Register  to view this content.
    Alf
    Last edited by Alf; 12-16-2015 at 06:40 AM.

  3. #3
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Macro inputs values between two numbers and sort accordingly

    You are The man!

    I appreciate your effort!

  4. #4
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro inputs values between two numbers and sort accordingly

    You are welcome.

    Thanks for feedback and rep

    Alf

    Ps If this solves your problem don't forget to mark thread "Solved" as per forum rules.

    To mark your thread solved do the following:
    -Go to the top of the first post
    -Select Thread Tools
    -Select Mark thread as Solved

  5. #5
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Macro inputs values between two numbers and sort accordingly

    One slight improvement needed. Let's say start is in 51 week, and end is in 6 week of new year I would need it to fill in 1,2,3,4,5,6 and 51,52. At the moment it doesn't react that way.

    Possible?

  6. #6
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro inputs values between two numbers and sort accordingly

    Not sure I understands excatly what you wish to do. I've made a change to the macro so when value reach 52 then it start going 1, 2, 3 and so forth. But this is only the cell value that get changed. I'm still using the i value to "find" the right offset cell to place value in.

    If this is not right could you upload a file showing what you wish.

    Please Login or Register  to view this content.
    Alf

  7. #7
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Macro inputs values between two numbers and sort accordingly

    As shown in yellow row.
    Attached Files Attached Files

  8. #8
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro inputs values between two numbers and sort accordingly

    Ok here is the modified code, have tested a bit and as far as I can see it works the way you wanted but you better do some testing yourself as well.

    The macro after clearing old data finds the range of data from FK3 to FK??.

    It then compaires value in FK3 with value in FL3. If FK3 greater than FL3 it assumes that cell value should start at 1 and increase it until it reaches the FL3 value.

    Then it takes the FK3 value and put in in the appropriate cell and increases this value untill it reaches 52.

    If FK3 value is less than FL3 it works the way it did before.

    Please Login or Register  to view this content.
    In the uploaded file you had pasted the macro in sheet1 but you can also go to the "Developer" tab, click the "Visual Basic" and in the new window click "Insert" and then "Module". Then paste the code in this window.

    Alf

  9. #9
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Macro inputs values between two numbers and sort accordingly

    Wonderful Alf!

    I appreciate your effort! Hopefully this will help someone else as well when dealing with weeks.

    Best regards.

  10. #10
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro inputs values between two numbers and sort accordingly

    Again you are welcome.

    One quick question. Looking at my calendar I see there are 53 weeks in the year 2015 but the max number in the macro is hard-coded to 52.

    Please Login or Register  to view this content.
    Perhaps you should change it?

    Alf

  11. #11
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Macro inputs values between two numbers and sort accordingly

    Well spotted! Thanks!

    When I attach macro in my original sheet I get an error (type mismatch, 13) although macro performs well. I want to ignore the error, I have tried with "On Error Resume Next" but it ruins the data.

    Please Login or Register  to view this content.
    Ideas?

  12. #12
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro inputs values between two numbers and sort accordingly

    Macro assumes all cells in range BM3:BN3 and down to be numbers, perhaps you should check if this is so.

    Have you tried to step through the macro to see where it finds the problem. As the line
    Please Login or Register  to view this content.
    is marked in red I assume this is the row that causes the problem and that could indicate that one cell value or the corresponding cell offset value is seen as text.

    Try to run this macro as a stand alone and see if any cells get red colored in the BM3:BN?? range

    Please Login or Register  to view this content.
    Alf

  13. #13
    Forum Contributor
    Join Date
    10-17-2014
    Location
    EU
    MS-Off Ver
    2013
    Posts
    114

    Re: Macro inputs values between two numbers and sort accordingly

    Cells in "BM3:BN" range contain formulas, but this doesn't seem to be a problem. It colours red only cells under last input in range "BM3:BN".

    Any possibility to skip the error msg?

  14. #14
    Forum Expert Alf's Avatar
    Join Date
    03-13-2004
    Location
    Gothenburg/Mullsjoe, Sweden
    MS-Off Ver
    Excel 2019 and not sure I like it
    Posts
    4,758

    Re: Macro inputs values between two numbers and sort accordingly

    It colours red only cells under last input in range "BM3:BN".
    Then there seems to something beneath the last visible value in the range "BM3:BN", can you delete the rows where you have the red cells or if that's not posible clear the range with red cells and do a rerun on the "ChkIfNum" macro and see if you have no more cells colored red.

    The command

    Please Login or Register  to view this content.
    starts from the bottom of the column BM and works its way upwards till it "meets" a cell with value but it will also "react" on for instance ' and the ' is a symbol you don't normaly see looking at a cell.

    When there is no more red cells in the BM:BN column you can run your "normal" macro and then there should be no error message.

    Alf

+ 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. [SOLVED] Sort Macro using Alphabetic & numbers
    By ElmerFud in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 09-04-2014, 08:23 AM
  2. Macro to sort merged cells with numbers in wrong format
    By adw223 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-30-2013, 09:37 AM
  3. [SOLVED] Sort Inputs From List Into Table
    By DontExcelAtMuch in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 06-20-2013, 03:39 PM
  4. [SOLVED] Formula problem, get and sort numbers between two values
    By Michaelice in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 05-04-2013, 03:36 AM
  5. [SOLVED] macro which copies all column values based on specific string inputs
    By buntalan80 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-12-2012, 03:08 PM
  6. Replies: 2
    Last Post: 08-13-2010, 12:15 AM
  7. Using Macro to Sort Names, Numbers & addresses
    By Tareq in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 03-01-2005, 11:06 AM

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