+ Reply to Thread
Results 1 to 10 of 10

Increment a range

  1. #1
    Registered User
    Join Date
    11-05-2014
    Location
    Calumet Mi
    MS-Off Ver
    2010
    Posts
    5

    Increment a range

    So I've got this code I copied and modified from another post to count consecutive 1's and list them out how many times each consecutive amount occurs.
    X groups of 2 consecutive, X groups of 3 consecutive...Etc

    if this is my input:
    Please Login or Register  to view this content.
    I get and output of(the top row I typed and the first column doesn't really matter):
    Please Login or Register  to view this content.
    Please Login or Register  to view this content.
    I need to do this for 217 rows from B2:NB2 to B218:NB218. Any help is appreciated!

    Later I will also have to list the largest consecutive group for each row if you have any ideas for that. I'm basically a VBA noob but I have a strong history of programming in many other languages.

    P.S. Also how would I clear those cells before I write the numbers...currently if I run it multiple times it keeps summing with the values currently in those cells.

  2. #2
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Increment a range

    Try it like this:

    Please Login or Register  to view this content.
    The largest consecutive group will be the rightmost column that is filled in your output with a number of 1 or greater
    Last edited by Bernie Deitrick; 11-05-2014 at 09:17 PM.
    Bernie Deitrick
    Excel MVP 2000-2010

  3. #3
    Registered User
    Join Date
    11-05-2014
    Location
    Calumet Mi
    MS-Off Ver
    2010
    Posts
    5

    Re: Increment a range

    Thankyou! Another quick question...Hows does excel do it's array indexing? Does it start at 1 and go up or does it start at 0?

    At this line:
    Please Login or Register  to view this content.
    Should the - 1 be there?

    Also I have data in column A that I don't want to erase. Rows(DataOutRow).ClearContents
    Clears the whole row. No biggie.
    Last edited by rcguymike; 11-06-2014 at 09:55 AM.

  4. #4
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Increment a range

    Rows and columns start at 1. I used -1 because that keeps the comparison within your range, since the final comparison is from the second to last column with the last column. For example, if you had B2:D2, you can only compare B to C and then C to D - two comparisons for three columns, so your would index 2 to 3 and not 2 to 4.

    Arrays may start at 0 or at 1, depending on your declaration, and whether you use an Option Base 1 (or 0) statement at the top or your module.

    To keep A filled, change

    Rows(DataOutRow).ClearContents

    to

    Range("B" & DataOutRow).Resize(1,Columns.Count-1).ClearContents
    Last edited by Bernie Deitrick; 11-06-2014 at 10:36 AM.

  5. #5
    Registered User
    Join Date
    11-05-2014
    Location
    Calumet Mi
    MS-Off Ver
    2010
    Posts
    5

    Re: Increment a range

    Starting with C=2 should take care of that... Lol but I suppose it would look proper if I start at 1 and use - 1. That's what I'm more familiar with anyways...
    Thanks again. I'm beginning to like excel.

  6. #6
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Increment a range

    Ah - I thought your range started in B: "I need to do this for 217 rows from B2:NB2 to B218:NB218"

  7. #7
    Registered User
    Join Date
    11-05-2014
    Location
    Calumet Mi
    MS-Off Ver
    2010
    Posts
    5

    Re: Increment a range

    I didn't have enough coffee today...It's comparing element 2 and element one with 1, and on and so forth, all the way to the last element and the last element - 1.
    The original:
    Please Login or Register  to view this content.
    makes sense if the array starts at 1 because then is starts at element 2(C2) and element 1(C2-1=B2) and compares them with 1, and on and so forth, all the way to NB2 and (NB2 - 1=NA2) and compares them to 1.

    Then it does that whole process for each row from B2:NB2 to B218:NB218

  8. #8
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Increment a range

    Really, if you are still having problems, it would be better if you uploaded your workbook. But I think you have a handle on the issue.

  9. #9
    Registered User
    Join Date
    11-05-2014
    Location
    Calumet Mi
    MS-Off Ver
    2010
    Posts
    5

    Re: Increment a range

    Quote Originally Posted by Bernie Deitrick View Post
    Really, if you are still having problems, it would be better if you uploaded your workbook. But I think you have a handle on the issue.
    It is working, thanks to you. The workbook contains sensitive information so I can't really upload it. I appreciate your help!

  10. #10
    Forum Expert
    Join Date
    02-11-2014
    Location
    New York
    MS-Off Ver
    Excel 365 (Windows)
    Posts
    6,351

    Re: Increment a range

    It would be easy to convert to values and just upload the sheet with the 1s and 0s (unless they are used to indicate ascii characters for a secret message! )

+ 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. Help with increment counter between date range
    By Rick_Hawk in forum Excel Formulas & Functions
    Replies: 6
    Last Post: 02-13-2014, 03:09 PM
  2. [SOLVED] Increment in Range of COUNTIF after adding a Row before Last Row.
    By dan-e in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 10-01-2013, 04:46 AM
  3. Increment cell range
    By djhatrick12 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 04-07-2011, 09:17 AM
  4. Apply set increment to a cell range
    By franko75 in forum Excel General
    Replies: 2
    Last Post: 01-13-2010, 06:43 AM
  5. Increment range reference in formula
    By XL_Newbie in forum Excel General
    Replies: 4
    Last Post: 12-08-2009, 01:46 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