+ Reply to Thread
Results 1 to 5 of 5

Macro to generate all numbers between two numbers

  1. #1
    Registered User
    Join Date
    06-24-2008
    Posts
    23

    Macro to generate all numbers between two numbers

    Hi everyone,

    I was able to cobble together a macro from another posting on another site and it works if I only put in one starting and ending number, but if I do more than one it gives me everything between all the numbers. What I want is to be able to put in a starting and ending number on multiple lines and for it to give me the number between the start and end per line. At the bottom of the post is my current code.

    For example if I put in the following:

    Starting Ending
    850 853
    900 903


    I get the following back:

    850
    851 This part is what I want
    852
    853
    everything from 853 to 899
    900
    901
    902
    903


    What I want to get is:

    850
    851
    852
    853
    900
    901
    902
    903


    Then lastly I'm also looking for macro language to output another string where each number is output separated by a comma.


    Thoughts? I tried a loop but with no luck.


    Please Login or Register  to view this content.
    Last edited by XL2008; 09-17-2015 at 01:41 PM.

  2. #2
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Macro to generate all numbers between two numbers

    Hi,

    Maybe :

    Please Login or Register  to view this content.

    Regards

  3. #3
    Registered User
    Join Date
    06-24-2008
    Posts
    23

    Re: Macro to generate all numbers between two numbers

    Works perfectly! I still have to solve the comma part, but I just saw a post today that seems to ask exactly what I need so I'll check that part out.

    Thank you so much!

  4. #4
    Forum Guru karedog's Avatar
    Join Date
    10-03-2014
    Location
    Indonesia
    MS-Off Ver
    2003
    Posts
    2,971

    Re: Macro to generate all numbers between two numbers

    Oops, didn't see the comma part request :

    Please Login or Register  to view this content.
    You are welcome, and thanks for the feedback.


    Regards

  5. #5
    Forum Guru MarvinP's Avatar
    Join Date
    07-23-2010
    Location
    Woodinville, WA
    MS-Off Ver
    Office 365
    Posts
    16,169

    Re: Macro to generate all numbers between two numbers

    Hi XL2008,

    See if this code gives you the numbers separated with commas. This is a User Defined Function (UDF) and see it work in the attached.
    Please Login or Register  to view this content.
    Attached Files Attached Files
    One test is worth a thousand opinions.
    Click the * Add Reputation below to say thanks.

+ 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: 7
    Last Post: 11-05-2014, 04:23 AM
  2. Is there any script that I generate 6 numbers of these numbers from the list?
    By dragon66 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 03-15-2014, 01:22 PM
  3. Replies: 1
    Last Post: 10-16-2013, 02:46 PM
  4. Macro Generate Numbers in Sequential Order
    By Rem0ram in forum Excel Programming / VBA / Macros
    Replies: 13
    Last Post: 07-09-2013, 08:30 AM
  5. Macro to generate list of numbers to link only one series to a key
    By cgkmal in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-06-2012, 01:27 AM
  6. Replies: 4
    Last Post: 10-11-2010, 05:13 AM
  7. Random numbers to generate amount between two numbers
    By maverickbv80 in forum Excel General
    Replies: 2
    Last Post: 09-08-2010, 11:21 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