+ Reply to Thread
Results 1 to 7 of 7

VBA Loop Sequential Numbers X Times Based on Cell Value

  1. #1
    Forum Contributor
    Join Date
    02-18-2014
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2013
    Posts
    197

    VBA Loop Sequential Numbers X Times Based on Cell Value

    Maybe it's just that it's 4:45pm and my brain is done, but I can't get this to work.

    I need a VBA loop that will give me sequential numbers in column D based on the value of cell B2. So if the value of B2 is 5, then beginning in D1, it'll do 1 2 3 4 5

    Any ideas?

  2. #2
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: VBA Loop Sequential Numbers X Times Based on Cell Value

    Try this code
    Please Login or Register  to view this content.
    < ----- Please click the little star * next to add reputation if my post helps you
    Visit Forum : From Here

  3. #3
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Loop Sequential Numbers X Times Based on Cell Value

    You can actually do that without VBA. Put this formula in D1 and copy down a few 100 rows.

    =IF(OR($B$2="", ROW()>$B$2), "", ROW())

    That will show 1 through X where X=B2.
    _________________
    Microsoft MVP 2010 - Excel
    Visit: Jerry Beaucaire's Excel Files & Macros

    If you've been given good help, use the icon below to give reputation feedback, it is appreciated.
    Always put your code between code tags. [CODE] your code here [/CODE]

    ?None of us is as good as all of us? - Ray Kroc
    ?Actually, I *am* a rocket scientist.? - JB (little ones count!)

  4. #4
    Forum Contributor
    Join Date
    02-18-2014
    Location
    Seattle, WA
    MS-Off Ver
    Excel 2013
    Posts
    197

    Re: VBA Loop Sequential Numbers X Times Based on Cell Value

    Yasser, that worked great! Thanks so much.

    JBeaucaire, that would work too, but I'm already in VBA mode doing some other tasks.

  5. #5
    Forum Expert
    Join Date
    04-23-2009
    Location
    Matrouh, Egypt
    MS-Off Ver
    Excel 2013
    Posts
    6,882

    Re: VBA Loop Sequential Numbers X Times Based on Cell Value

    You're welcome. Glad I can offer some help

  6. #6
    Forum Expert JBeaucaire's Avatar
    Join Date
    03-21-2004
    Location
    Bakersfield, CA
    MS-Off Ver
    2010, 2016, Office 365
    Posts
    33,492

    Re: VBA Loop Sequential Numbers X Times Based on Cell Value

    For chuckles, another version that accomplishes the same thing without a loop, so no matter want the number is in B2, even 150k, it will only write to the sheet twice and be done:

    Please Login or Register  to view this content.

  7. #7
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,525

    Re: VBA Loop Sequential Numbers X Times Based on Cell Value

    Simply
    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. [SOLVED] Return Sequential Numbers Based on Unique Values
    By HangMan in forum Excel Formulas & Functions
    Replies: 11
    Last Post: 11-06-2015, 08:13 PM
  2. [SOLVED] re-numbering a list of numbers based on another list of numbers to get a sequential order
    By ryan.wherry in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 11-10-2014, 03:27 PM
  3. Replies: 3
    Last Post: 12-21-2012, 06:03 PM
  4. [SOLVED] VBA loop to copy a worksheet a number of times, assign name each time based on loop number
    By TBG in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-29-2012, 10:54 PM
  5. Macro to distinguish sequential numbers and report a value to a different cell
    By capnhud in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 10-10-2011, 08:42 AM
  6. Conditional format based on non sequential numbers
    By Porsche in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 11-15-2009, 03:59 PM
  7. inputting sequential numbers from one cell
    By stephen1000 in forum Excel General
    Replies: 24
    Last Post: 11-29-2008, 05:24 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