+ Reply to Thread
Results 1 to 19 of 19

Macro to Delete Rows and Renumber Items after

  1. #1
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Bradford PA
    MS-Off Ver
    Excel 2010
    Posts
    250

    Macro to Delete Rows and Renumber Items after

    Looking for a userform commandbutton macro "CommandButton1" to initiate a deletion of rows. Essentially "Combobox1" is a list of "Text" rows in columnA (after row16). I want the commandbutton to delete the "Text" row chosen in the combobox and all rows below it until the next "Text" row. After this I want all "Number" rows below the chosen "Text" row to be renumbered by subtracting "1.000". The sequence of order I guess doesn't really matter as long as the desired outcome is achieved (meaning if for vba purposes it is better to renumber all rows below the "Text" row chosen then delete the "Text" row and rows between next "Text" row that is perfectly fine)

  2. #2
    Forum Expert Olly's Avatar
    Join Date
    09-10-2013
    Location
    Darlington, UK
    MS-Off Ver
    Excel 2016, 2019, 365
    Posts
    6,284

    Re: Macro to Delete Rows and Renumber Items after

    Can you please attach a workbook, showing what you currently have, and what your required outcome looks like.
    let Source = #table({"Question","Thread", "User"},{{"Answered","Mark Solved", "Add Reputation"}}) in Source

    If I give you Power Query (Get & Transform Data) code, and you don't know what to do with it, then CLICK HERE

    Walking the tightrope between genius and eejit...

  3. #3
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Bradford PA
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Macro to Delete Rows and Renumber Items after

    Quote Originally Posted by Olly View Post
    Can you please attach a workbook, showing what you currently have, and what your required outcome looks like.
    Olly,

    Sure and thanks for your help in advance. Essentially WS "ARG-130829" would be the original user hits commandbutton "ADD/DELETE CATEGORY". This generates Userform7. User selects the desired category and hits the userform7 commandbutton "Delete". From here the copied worksheet "ARG-130829(2)" is what the outcome would look like. In this scenario the user would have chosen the category "Employee Participation". The commandbutton then deleted this row and all rows below it to the next "Text" row. It renumbered all values after (besides those deleted of course) by subtracting a value of 1.000. Finally it removed it from the categories section seen in cell A9 on the original worksheet and moved the other categories up in this section. (If you see A8:A15 and D8:D15 are a listing of all "Text" rows in the data file A8 starts the list and it is carried over from A15 to D8 for format purposes.)

    Forum Example.xlsm
    Last edited by jaredmccullough; 04-08-2014 at 10:43 PM.

  4. #4
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Bradford PA
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Macro to Delete Rows and Renumber Items after

    Bump for help.....

  5. #5
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to Delete Rows and Renumber Items after

    Hi jared

    Try replacing your UserForm7 Code with this
    Please Login or Register  to view this content.
    John

    If you have issues with Code I've provided, I appreciate your feedback.

    In the event Code provided resolves your issue, please mark your Thread as SOLVED.

    If you're satisfied by any members response to your issue please use the star icon at the lower left of their post.

  6. #6
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Bradford PA
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Macro to Delete Rows and Renumber Items after

    Quote Originally Posted by jaslake View Post
    Hi jared

    Try replacing your UserForm7 Code with this
    Please Login or Register  to view this content.
    John it seemed to work fairly close to as intended. The only 2 minor adjustments that I would like to as to be made is:

    1.) the first being if you look at cells A8:D15 there is a "Category" which matches the one being deleted. This is used to scroll through the worksheet. Along with deleting the rows I would as well like it to remove this "category" from the A8:D15 range and move those values up/across. If you look at the actual workbook you will see what I mean. One of the grey "Header" rows after row17 matches one of the grey "Categories" in A8:D15.

    2.) The second being that after the user selects the item from the CombBox and hits commandbutton2 would it be plausible to reset the combobox as the Item that was deleted still remains in the combobox.

    Thanks for your help

  7. #7
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to Delete Rows and Renumber Items after

    Hi jared

    Try the Code in the attached...
    Attached Files Attached Files

  8. #8
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Bradford PA
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Macro to Delete Rows and Renumber Items after

    John,

    One issue for undetermined reason it deletes the static text out of E10 and E11 when the code is ran?? Any suggestions? Other than that the code worked as intended

  9. #9
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to Delete Rows and Renumber Items after

    Hi Jared

    Had to change one line of Code in Module1...please replace Module1 Code with this
    Please Login or Register  to view this content.

  10. #10
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Bradford PA
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Macro to Delete Rows and Renumber Items after

    John,

    I was doing some final testing and ran into a few issues. I have attached the newest revision of my workbook with your code. The only adjustment really is that the previously mentioned "Userform7" has now become "Userform05" I have added the adjustment to the code but ran into 2 problems. I have generated a new WS entitled "ARG-NEW AUDIT" just to test things on.

    Problem1: Before running the code provided view another macro I have. This is worksheet code located on WS "ARG-130829" and WS "ARG-NEW AUDIT". How to test is hit a cell in the Categories "Box" (cells A8:D15) and if you watch it will scroll the matching row to the top of the page. When I run your macro it removes this feature both from the active WS but as well as the other WS. Kind of confused about this one???

    Problem2: The second problem is that in the "Categories Box" (cells A8:D15) in a few trial attempts it did not adjust the categories over appropriately.

    Attached Workbook: (PSM-14-02) PSAudit.xlsm

  11. #11
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to Delete Rows and Renumber Items after

    Hi jared

    Problem 1 issue was caused by Application.EnableEvents being set to False. This has been corrected (I believe) in the attached.

    Problem 2 issue was caused because, in the original Sample File, Column D (D8:D15) was not populated so the Code was not taking these Cells into account. This has been corrected (I believe) in the attached.

    I've tested rather extensively...let me know of issues...
    Attached Files Attached Files

  12. #12
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Bradford PA
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Macro to Delete Rows and Renumber Items after

    (PSM-14-02) PSAudit EXAMPLE.xlsm

    John,

    For Problem2 if it is not to much hassle....the goal would be for the "Cateogories Box" (A8:D15) to function as a whole so if you were to remove an item from the "A" side the "D" side would shift over accordingly. I have manually adjusted the categories box in the attached workbook to show an example. WS "ARG-130829" would be the original file and WS "ARG-NEW AUDIT" would be what it would look like after the category "Contractors" was deleted from cell A14. If you notice if there is items in D8:D15 they shift over accordingly. (I know this may seem weird but I plan on having a function to add as well so it will be importanat they are sequentially in order)

  13. #13
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to Delete Rows and Renumber Items after

    Hi jared

    I need to step out for several hours...will look at it this afternoon.

  14. #14
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Bradford PA
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Macro to Delete Rows and Renumber Items after

    John,

    Please don't feel any need to address right away at your convenience any help would be appreciated.

  15. #15
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to Delete Rows and Renumber Items after

    Hi jared

    Replace Module 4 Code with this
    Please Login or Register  to view this content.
    Attached Files Attached Files

  16. #16
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Bradford PA
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Macro to Delete Rows and Renumber Items after

    John,

    Seems to work as intended (may I ask what causes the slight hesitation in the code)? As well you had mentioned adjusting the column width so you couldn't see the numbers? where might I do this at?

  17. #17
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to Delete Rows and Renumber Items after

    Hi jared

    Forgot to give you the Code Changes for UserForm5...replace UserForm5 Code with this
    Please Login or Register  to view this content.

  18. #18
    Forum Contributor
    Join Date
    04-23-2012
    Location
    Bradford PA
    MS-Off Ver
    Excel 2010
    Posts
    250

    Re: Macro to Delete Rows and Renumber Items after

    John,

    Works beautifully and I was able to make the adjustments to the column width using the 1;0 setting in the properties. Thanks for all your help. If interested keep an eye out as I plan on making a post to do the opposite to add a category in between 2 categories (if you couldn't tell by the userform). Again I cant thank you enough.

    Jared

  19. #19
    Forum Expert jaslake's Avatar
    Join Date
    02-21-2009
    Location
    Atwood Lake in Mid NE Ohio...look it up.
    MS-Off Ver
    Excel 2010 2019
    Posts
    12,749

    Re: Macro to Delete Rows and Renumber Items after

    Hi Jared

    You're welcome...glad I could help. Thanks for the Rep.

    If this resolves your issue please mark your Thread as SOLVED.

    New quick method:
    Select Thread Tools-> Mark thread as Solved. To undo, select Thread Tools-> Mark thread as Unsolved.

    Or you can use this way:
    How to mark a thread Solved
    Go to the first post
    Click edit
    Click Go Advanced
    Just below the word Title you will see a dropdown with the word No prefix.
    Change to Solved
    Click Save

+ 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. detele rows but renumber in sequnce
    By steve111 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 03-03-2014, 02:45 PM
  2. Delete rows that do not match items from listbox
    By pietras152 in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-12-2013, 01:08 PM
  3. [SOLVED] Renumber rows with the inclusion of blank
    By fanx in forum Excel Formulas & Functions
    Replies: 7
    Last Post: 08-01-2013, 12:49 PM
  4. [SOLVED] Delete rows that have data less than 20 items or less than value of £300
    By Crowbar via OfficeKB.com in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 10-24-2005, 05:05 PM
  5. [SOLVED] Macro for Excel to add up items and delete extra lines?
    By Fiero84 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-18-2005, 10: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