+ Reply to Thread
Results 1 to 8 of 8

Insert new row under specified data

  1. #1
    Registered User
    Join Date
    11-04-2014
    Location
    london
    MS-Off Ver
    2010
    Posts
    24

    Insert new row under specified data

    Hello,

    I have a spreadsheet that has a number of columns containing different values and data. The rows are sorted by month, which is displayed column C. Is there a way to have a VBA which loops through the rows and finds the last time each month was written, and then inserts a new blank row underneath it. I have some code below which inserts a new row after every month of January but only want it to insert a row after the last January, so that the months are separated in a block.

    Thank you in advance!

    Please Login or Register  to view this content.

  2. #2
    Forum Contributor
    Join Date
    01-30-2013
    Location
    Wales
    MS-Off Ver
    Excel 2013
    Posts
    231

    Re: Insert new row under specified data

    How about.

    Instead of looking for January look for when the value of one cell is different to the value of the cell below it?

    Does that help at all?

    Chris
    Click * below if this answer helped

  3. #3
    Registered User
    Join Date
    11-04-2014
    Location
    london
    MS-Off Ver
    2010
    Posts
    24

    Re: Insert new row under specified data

    Yes that may well be a better idea, Chris.

    Would you know how to do that and apply it, not just for Jan, but also Feb etc...

    Thank you

  4. #4
    Forum Expert
    Join Date
    10-09-2012
    Location
    Dallas, Texas
    MS-Off Ver
    MO 2010 & 2013
    Posts
    3,049

    Re: Insert new row under specified data

    It seems you just want to find the bottom january then insert a row, so why not look for it THEN insert a row.

    Set FindRow = ActiveSheet.Range("A:A").Find(What:="January", LookIn:=xlValues)
    And if you solely need the row number, you can use this after:

    Dim FindRowNumber As Long
    .....
    FindRowNumber = FindRow.Row
    Please ensure you mark your thread as Solved once it is. Click here to see how.
    If a post helps, please don't forget to add to our reputation by clicking the star icon in the bottom left-hand corner of a post.

  5. #5
    Forum Contributor
    Join Date
    06-22-2011
    Location
    somerset
    MS-Off Ver
    365
    Posts
    328

    Re: Insert new row under specified data

    Please Login or Register  to view this content.
    Sub Reputation()
    Dim Problem as Variant
    Dim Reputation as Integer
    For Each Problem in Forum.Threads
        If Problem.Title = "*[Solved]*" and Solver.Name = "Leon V (AW)" Then Reputation = Reputation + 1
    Next Problem
    End Sub

  6. #6
    Forum Contributor
    Join Date
    01-30-2013
    Location
    Wales
    MS-Off Ver
    Excel 2013
    Posts
    231

    Re: Insert new row under specified data

    Hi Rookie

    You are already in a loop. Remove the check to see if Inserted = False, and all references to Inserted and it should work as it is.

    I haven't tested the code yet so beware!!


    Best of luck.

    Chris
    Please Login or Register  to view this content.
    Last edited by Chris 53; 11-07-2014 at 04:42 AM. Reason: Added some code

  7. #7
    Registered User
    Join Date
    11-04-2014
    Location
    london
    MS-Off Ver
    2010
    Posts
    24

    Re: Insert new row under specified data

    Hi, thanks for your help so far. Unfortunately, it isn't quite working and it keeps on adding a new line under each time the month is written, not just after the last time. Any ideas why? Thanks

  8. #8
    Forum Contributor
    Join Date
    01-30-2013
    Location
    Wales
    MS-Off Ver
    Excel 2013
    Posts
    231

    Re: Insert new row under specified data

    I did say I hadn't tested it.

    try the code below which I have tested.

    Chris

    Please Login or Register  to view this content.
    Last edited by Chris 53; 11-07-2014 at 07:51 AM. Reason: Insert comments in code

+ 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. [SOLVED] Loop through entire sheet, Insert row, copy row data, paste row data, delete row
    By Hyperdude in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-19-2012, 01:46 AM
  2. Copy paste data, insert rows, insert data and change . to -
    By xWiZardx in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-16-2010, 01:44 AM
  3. Replies: 5
    Last Post: 09-15-2008, 07:04 PM
  4. Refresh All Workbook Data - incoming data insert properties
    By dnnr in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 07-26-2007, 11:14 AM
  5. [SOLVED] insert entire row for new data, external data range doesnt work
    By orlya1 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 04-03-2006, 03:45 PM

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