Results 1 to 3 of 3

Macro to insert row if cell(i,1) notequal cell(i,1)+1 and insert certain values in row.

Threaded View

  1. #1
    Registered User
    Join Date
    10-15-2013
    Location
    Stockholm, Sweden
    MS-Off Ver
    Excel 2007
    Posts
    2

    Macro to insert row if cell(i,1) notequal cell(i,1)+1 and insert certain values in row.

    Hi,
    I have data with 20000 observations over time. Time span is 1969 to 2011 for different categories. Not for every category there are observations for every year, so I would like to insert a row for the missing years, containing the value 0 in the "observation" cell.

    Example:

    Year Age Observation
    1969 0 4
    1970 0 17
    1972 0 6
    ...
    ...
    1969 1 5
    1970 1 22
    ....

    You see for example that for age 0 the year 1971 is missing, as there are no observations. I would like to insert a row here, indicating 0 obervations.

    My macro looks like this so far:

    Sub macro1()
    Dim i As Long
    i = 3
    Do Until Trim(Cells(i, 1)) = ""
    If Cells(i, 1) <> Cells(i - 1, 1)+1 Then
    Cells(i, 1).EntireRow.Insert
    Cell(i + 1, 1) = Cell(i, 1)+1
    Cell(i + 1, 2) = Cell(i, 2)
    Cell(i + 1, 3) = 0
    i = i + 2
    Else
    i = i + 1
    End If
    Loop
    End Sub


    It is not working...what am I doing wrong?


    Thanks a lot!!
    Last edited by mareike; 10-15-2013 at 10:59 AM.

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Macro to insert cell values in another sheet depending on value and format
    By adw223 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2013, 03:57 PM
  2. Replies: 1
    Last Post: 07-11-2012, 01:10 PM
  3. After insert new record, insert values in row based on first cell in row
    By frankienap in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-04-2012, 11:36 AM
  4. [SOLVED] Macro to insert to move values of a cell to next cell in the same row
    By Macro man in forum Excel General
    Replies: 1
    Last Post: 08-06-2005, 01:05 AM
  5. Macro to insert formula result into range with zero values in cell
    By JPS in forum Excel Programming / VBA / Macros
    Replies: 9
    Last Post: 07-06-2005, 01:05 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