+ Reply to Thread
Results 1 to 9 of 9

Add and Remove Rows based on Cells

  1. #1
    Registered User
    Join Date
    11-17-2014
    Location
    California
    MS-Off Ver
    2013
    Posts
    5

    Add and Remove Rows based on Cells

    Hello,

    I'm creating a weekly presentation spreadsheet for a military unit that will change hands frequently and I can't rely on users to know how to right click and add or delete a row.

    In order to uncomplicate the procedure for users, I've added two cells - one for a member's rank, and the other for their last name. The list is required to be in rank order and then alphabetical (I realize that it is not this way in the attached image). When a user enters a name that does not exist in the list and the user clicks "Add Member", I need a macro to add a row in the correct place with that member's rank and name. Alternatively, when an existing member's name and rank are entered and "Remove Member" is clicked, I need a macro that will delete that row. Any help with this is greately appreciated - I'm way in over my head on this one.

    Edit: I've included a sample worksheet with examples as suggested by AlphaFrog. If any more clarification is required, feel free to ask.
    Edit 2: Uploaded .xlsm as per AliGW.

    Rank order from lowest to highest is:
    AB, Amn, A1C, SrA, SSgt, TSgt, MSgt, SMSgt, CMSgt, 2nd Lt, 1st Lt, Capt, Maj, Lt Col, Col

    Capture.PNG
    Attached Files Attached Files
    Last edited by anderb16; 07-29-2017 at 05:43 AM. Reason: Edited for content

  2. #2
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Add and Remove Rows based on Cells

    I would be best if you attach a sample workbook. Make sure there is just enough data to demonstrate your need. Include a BEFORE sheet and an AFTER sheet in the workbook if needed to show the process you're trying to complete or automate. Make sure your desired results are shown, mock them up manually if necessary.

    Remember to desensitize the data.

    Click on GO ADVANCED and then scroll down to Manage Attachments to open the upload window.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  3. #3
    Registered User
    Join Date
    11-17-2014
    Location
    California
    MS-Off Ver
    2013
    Posts
    5

    Re: Add and Remove Rows based on Cells

    Thanks AlphaFrog. I've edited my original post to include the example workbook.
    Last edited by AliGW; 07-29-2017 at 03:29 AM. Reason: Unnecessary quotation removed.

  4. #4
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,913

    Re: Add and Remove Rows based on Cells

    The attached workbook is sans macros - it's an .xlsx file. You need to provide the macro-enabled (.xlsm) version.
    Ali


    Enthusiastic self-taught user of MS Excel who's always learning!
    Don't forget to say "thank you" in your thread to anyone who has offered you help.
    You can reward them by clicking on * Add Reputation below their user name on the left, if you wish.

    Forum Rules (updated August 2023): please read them here.

  5. #5
    Registered User
    Join Date
    11-17-2014
    Location
    California
    MS-Off Ver
    2013
    Posts
    5

    Re: Add and Remove Rows based on Cells

    The workbook didn't yet contain any macros, so I hadn't saved it as such, but good catch - thanks for pointing that out! Fixed
    Last edited by anderb16; 07-29-2017 at 05:47 AM.

  6. #6
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,913

    Re: Add and Remove Rows based on Cells

    OK, understood. I took your opening post to mean that you needed the two macros tweaking.

  7. #7
    Registered User
    Join Date
    11-17-2014
    Location
    California
    MS-Off Ver
    2013
    Posts
    5

    Re: Add and Remove Rows based on Cells

    I wish. I've written very little VBA on other projects and I'm just not at a point where I could get this project done in the time allotted by trying to piece together stuff from the internet and modify it the way I need.

  8. #8
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,643

    Re: Add and Remove Rows based on Cells

    Try the attached file.

    I did change your table a little. It made coding the macros easier:
    • The Rank and Name are separated into two columns.
    • The Indirect functions in the formulas were removed.
    Attached Files Attached Files
    Last edited by AlphaFrog; 08-01-2017 at 01:44 AM.

  9. #9
    Forum Moderator AliGW's Avatar
    Join Date
    08-10-2013
    Location
    Retired in Ipswich, Suffolk, but grew up in Sawley, Derbyshire (England)
    MS-Off Ver
    MS 365 Subscription Insider Beta Channel v. 2404 (Windows 11 22H2 64-bit)
    Posts
    80,913

    Re: Add and Remove Rows based on Cells

    No file attached ...

+ 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. remove duplicate rows based on condition
    By stephme55 in forum Excel General
    Replies: 1
    Last Post: 08-15-2016, 07:34 PM
  2. Remove rows based on word in column
    By wonderd in forum Excel Programming / VBA / Macros
    Replies: 22
    Last Post: 06-06-2016, 05:55 PM
  3. [SOLVED] Remove Rows based upon list of search terms, copy removed rows to new sheet
    By sam103329 in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 02-19-2015, 08:47 PM
  4. Remove Rows based on the value of a drop down box.
    By jcobbexcel in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 02-05-2014, 12:52 AM
  5. Remove Rows based upon list of search terms, copy removed rows to new sheet
    By sam103329 in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 12-26-2013, 10:32 PM
  6. [SOLVED] Find duplicates rows, sum cells then remove duplcate rows
    By Wagstaff in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 09-22-2013, 09:37 AM

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