+ Reply to Thread
Results 1 to 8 of 8

Increment a number based on the text in the adjacent column

  1. #1
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Increment a number based on the text in the adjacent column

    Hello,

    In column B i will only have 3 values, either S, U or M. I need a counter in Column A that starts at 1 and for each time column B has a U or M increment that number in column A. If Column B contains S, then leave A blank, no counter needed for those. I need to implement this in VBA, not in the worksheet.

    Any thoughts?

    I. E. This is an example of how it would look.

    Col A ColB
    ----- -----
    S
    1 M
    2 U
    S
    3 U
    4 U
    S
    5 M


    I thought this would be a simple task, however I am finding out that it is not so easy!!

  2. #2
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Increment a number based on the text in the adjacent column

    Try this
    A1: =IF(OR(B1={"M","U"}),COUNTIF(B$1:B1,"<>S"),"")

    Copy that formula down through A8

    Is that something you can work with?
    Ron
    Former Microsoft MVP - Excel (2006 - 2015)
    Click here to see the Forum Rules

  3. #3
    Forum Expert NBVC's Avatar
    Join Date
    12-06-2006
    Location
    Mississauga, CANADA
    MS-Off Ver
    2003:2010
    Posts
    34,898

    Re: Increment a number based on the text in the adjacent column

    I think this part was important to the OP....

    I need to implement this in VBA, not in the worksheet
    Where there is a will there are many ways.

    If you are happy with the results, please add to the contributor's reputation by clicking the reputation icon (star icon) below left corner

    Please also mark the thread as Solved once it is solved. Check the FAQ's to see how.

  4. #4
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Increment a number based on the text in the adjacent column

    Ron, thanks so much, this is working the way I want, but with a few little corrections to it. However when I put this in VBA to copy to the last row I am getting error about range of object method. Below is the code. I know this may be a different thread, but do you have any ideas?

    Please Login or Register  to view this content.

  5. #5
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Increment a number based on the text in the adjacent column

    Quote Originally Posted by NBVC View Post
    I think this part was important to the OP....
    Oh, pipe down! I've been so busy at work that I've hardly had time to even look at the forum! ...and, of course, you're correct.

  6. #6
    Administrator FDibbins's Avatar
    Join Date
    12-29-2011
    Location
    Duncansville, PA USA
    MS-Off Ver
    Excel 7/10/13/16/365 (PC ver 2310)
    Posts
    52,938

    Re: Increment a number based on the text in the adjacent column

    are we going to use mud or oil for this 1? or maybe just sledge hammers in the deep end of the swimming pool?
    lol
    1. Use code tags for VBA. [code] Your Code [/code] (or use the # button)
    2. If your question is resolved, mark it SOLVED using the thread tools
    3. Click on the star if you think someone helped you

    Regards
    Ford

  7. #7
    Forum Contributor
    Join Date
    07-03-2012
    Location
    United States
    MS-Off Ver
    Excel 2010
    Posts
    139

    Re: Increment a number based on the text in the adjacent column

    Sometimes when you stare at code all day, ya get a little crosseyed, and that must have been what happend to me here!!

    I got this corrected, "" in the wrong place, line that was corrected and correct version below

    BAD!!
    Please Login or Register  to view this content.
    Good
    Please Login or Register  to view this content.
    Issue resolved, thanks Ron

  8. #8
    Forum Expert Ron Coderre's Avatar
    Join Date
    03-22-2005
    Location
    Boston, Massachusetts
    MS-Off Ver
    2013, 2016, O365
    Posts
    6,996

    Re: Increment a number based on the text in the adjacent column

    1) You're welcome
    2) If there will be no blanks within the Col_B range....
    Try something like this:
    Please Login or Register  to view this content.
    Does that help?
    Last edited by Ron Coderre; 07-27-2012 at 10:48 PM.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

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