Results 1 to 3 of 3

Need help with a macro to add & remove rows in specific locations

Threaded View

  1. #1
    Registered User
    Join Date
    01-25-2013
    Location
    Vermont, Dakota
    MS-Off Ver
    Excel 2007
    Posts
    22

    Question Need help with a macro to add & remove rows in specific locations

    Hello -

    I've only had tremendous results from this community and have learned a lot so I return with my newest problem. I'm working on creating a sheet to manage personnel and realized that my life could be made much easier using vba, the trouble is I'm having trouble coming up with it. I've attached what I think is a good example of what I'm looking for that I hope some of you can help me with.

    addpersrempersexample.xlsx

    The task has to do with adding two rows in changing (though following a consistent pattern) locations while also allowing for the removal of the row pair through the click of buttons. It will be much clearer in the example.

    Currently I use a primitive macro too add people and I am forced to manually remove them as I couldn't come up with a suitable removal method:

    Public Sub AddPers()
        Dim offsval As Range
        Set offsval = Range("A4")
        Range("B28").Select
        ActiveCell.Offset(1, 0).EntireRow.Insert
        ActiveCell.EntireRow.Copy ActiveCell.Offset(1, 0).EntireRow
        ActiveCell.Offset(offsval, 0).Activate
        ActiveCell.Offset(1, 0).EntireRow.Insert
        ActiveCell.EntireRow.Copy ActiveCell.Offset(1, 0).EntireRow
        ActiveCell.Offset(-5, 0).Activate
        Range("A4").Value = 1 + Range("A4").Value
    End Sub
    In the code offsval is initially equal to 5, the distance between the rows in the first move
    when I remove people I have to be careful to ensure the offsval is changed to be correct

    another minor problem with this code I haven't devoted too much thought to is that the added rows are placed second rather than at the bottom - i understand why this is, but haven't thought of an easy solution given my implementation.


    any direction or help is much appreciated , especially in regards to easily removing people !

    steve

    **** sorry about typo in B8 on example just caught it
    Last edited by thesteve; 01-16-2015 at 03:49 PM. Reason: added apology

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 22
    Last Post: 08-15-2014, 03:06 PM
  2. excel macro to remove specific columns and rows + remove duplicate
    By garrywelson in forum Excel Programming / VBA / Macros
    Replies: 12
    Last Post: 01-17-2013, 12:03 PM
  3. Remove rows based on specific condition
    By shinichi_nguyen in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-27-2012, 02:30 PM
  4. vba macro to remove rows if different from specific cell
    By Hyflex in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-06-2011, 01:28 PM
  5. [SOLVED] Advanced function to remove specific rows
    By nemadrias in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 07-10-2006, 03:04 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