+ Reply to Thread
Results 1 to 8 of 8

For Loop in Macro for generating continuous nos with a condition

  1. #1
    Registered User
    Join Date
    01-26-2013
    Location
    chennai
    MS-Off Ver
    Excel 2007
    Posts
    20

    Post For Loop in Macro for generating continuous nos with a condition

    I am new to Macros.

    i am using a for loop for generating continuous numbers in A column and i would like to add a condition.

    Condition:
    If column B2 has a value then the For-loop should generate the next number in A3 and it goes on...if B3 has a value then it should generate the next series of no in A4

    A B
    No Name
    1 sam
    2


    Kindly help me on this.

  2. #2
    Forum Expert
    Join Date
    07-15-2012
    Location
    Leghorn, Italy
    MS-Off Ver
    Excel 2010
    Posts
    3,431

    Re: For Loop in Macro for generating continuous nos with a condition

    you don't need a loop
    Please Login or Register  to view this content.
    If solved remember to mark Thread as solved

  3. #3
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,884

    Re: For Loop in Macro for generating continuous nos with a condition

    Another approach would be to copy and paste the following code into the worksheet module (not a regular module). This method will automatically add and increase the number in column A when you enter the name in column B.

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    01-26-2013
    Location
    chennai
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: For Loop in Macro for generating continuous nos with a condition

    @patel45 - Thx for your quick respone..bt your code is not working as i expected

  5. #5
    Registered User
    Join Date
    01-26-2013
    Location
    chennai
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: For Loop in Macro for generating continuous nos with a condition

    @Mumps1 - I copy pasted your code and it works perfectly fine..Thanks a lot.
    But in couple of scenario's the counting starts from '1' again.
    Scenario:
    if one of the cell in B column is blank and the next cell i fill in some value. It starts the counting from 1 again.

  6. #6
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,884

    Re: For Loop in Macro for generating continuous nos with a condition

    Try:

    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    01-26-2013
    Location
    chennai
    MS-Off Ver
    Excel 2007
    Posts
    20

    Re: For Loop in Macro for generating continuous nos with a condition

    if i merge column A12 to A15, then again it starts the counting from 1 from A16.

  8. #8
    Forum Expert Mumps1's Avatar
    Join Date
    10-10-2012
    Location
    Toronto, Canada
    MS-Off Ver
    Excel 2010, 2013
    Posts
    7,884

    Re: For Loop in Macro for generating continuous nos with a condition

    Merged areas most often cause problems in Excel. You should avoid them whenever possible. I'm not really sure how I can help you. Perhaps someone else in the forum might have a solution.

+ 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