Consulting

Results 1 to 4 of 4

Thread: Add consecutive numbers

  1. #1

    Add consecutive numbers

    Hi,

    Sorry my mind has gone completely blank... I have this:

    <Attached spreadsheet> (have added red what i want the code to do)

    Basically, if there is a number in Column "C", I want the code to insert a number (starting at 1) in Column "B". Then goto the next cell, if there is a value there, put a "2" in the next one, until there is no value in column C. I would much appreciate peoples help as my brain has died

    Thanks

  2. #2
    Knowledge Base Approver
    The King of Overkill!
    VBAX Master
    Joined
    Jul 2004
    Location
    Rochester, NY
    Posts
    1,727
    Location
    Do you need code to do it? You could just put into B2
    =IF(ISNUMBER(C2),B1+1,"")
    And fill down

    If you really want VBA..[vba] With Range("C2", Cells(Rows.Count, "C").End(xlUp)).Offset(0, -1)
    .Formula = "=ROW()" & IIf(.Row > 1, "-" & .Row - 1, "")
    .Value = .Value
    End With[/vba]
    Matt

  3. #3
    Administrator
    VP-Knowledge Base VBAX Grand Master mdmackillop's Avatar
    Joined
    May 2004
    Location
    Scotland
    Posts
    14,489
    Location
    Enter 1 in the first cell, hold down Control and drag the fill button.
    MVP (Excel 2008-2010)

    Post a workbook with sample data and layout if you want a quicker solution.


    To help indent your macros try Smart Indent

    Please remember to mark threads 'Solved'

  4. #4
    Yes thank you. A very simple task on its own in excel but its part of a much larger routine. Thank you though, it is much appreciated

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •