+ Reply to Thread
Results 1 to 8 of 8

Compute Month Based on Cell Content

  1. #1
    Registered User
    Join Date
    06-28-2007
    Posts
    27

    Compute Month Based on Cell Content

    Hi All,

    i'm having trouble trying to figure this out. I have a column with month numbers and random numbers of empty rows in between. For example,

    7
    blank row
    blank row
    3
    blank row
    blank row
    blank row
    blank row
    blank row
    blank row
    11
    blank row
    blank row
    blank row

    As I said before, each number represents a month (7=July, 3=March, etc). I would like for my macro to calculate the month number based on the number on the row above. If it reaches 12, then it should start with 1 again. Essentially, the output from the example above should be as follows:

    7
    8
    9
    3
    4
    5
    6
    7
    8
    9
    11
    12
    1
    2

    I've gotten my macro to thus far add only 1 number but i can't get it to loop. I've added the code below:

    Any help is highly appreciated! Happy Holidays!
    J.

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor VBA Noob's Avatar
    Join Date
    04-25-2006
    Location
    London, England
    MS-Off Ver
    xl03 & xl 07(Jan 09)
    Posts
    11,988
    See link

    http://www.contextures.com/xlDataEntry02.html#Fill

    Just change say
    Please Login or Register  to view this content.
    to
    Please Login or Register  to view this content.
    VBA Noob
    _________________________________________


    Credo Elvem ipsum etian vivere
    _________________________________________
    A message for cross posters

    Please remember to wrap code.

    Forum Rules

    Please add to your signature if you found this link helpful. Excel links !!!

  3. #3
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-28-2007
    Posts
    27
    Shg and Noob,

    Thanks for your code. It worked up to a point. It does add the numbers but now I would like to limit the number only up to 12. After 12, it should restart with 1 again.

    Thanks in advance,
    J.

  5. #5
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    Sorry, my code was completely wrong. This works:
    Please Login or Register  to view this content.

  6. #6
    Registered User
    Join Date
    06-28-2007
    Posts
    27
    Thanks shg...that definitely worked.

    Now, let me ask you...If now I had the year in the next column and would like to copy the year down but the year would change everytime a 1 (or january) was found. For example, if I had

    4 2006
    5
    6
    7
    8
    9
    11
    12
    1
    2

    I would want it to do:

    4 2006
    5 2006
    6 2006
    7 2006
    8 2006
    9 2006
    11 2006
    12 2006
    1 2007
    2 2007

    Thanks for your help.

    J.

  7. #7
    Forum Expert shg's Avatar
    Join Date
    06-20-2007
    Location
    The Great State of Texas
    MS-Off Ver
    2003, 2010
    Posts
    40,678
    That's more likely to break based on the data you've entered ...
    Please Login or Register  to view this content.

  8. #8
    Registered User
    Join Date
    06-28-2007
    Posts
    27
    Shg,
    thanks for your reply. This worked great except that it also changed the cell contents for those that were already populated. But i found the solution.

    Thanks again,
    J.

+ 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