+ Reply to Thread
Results 1 to 15 of 15

Macro to delete the rows automatically

  1. #1
    Registered User
    Join Date
    06-08-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    14

    Macro to delete the rows automatically

    Hi I have a requirement
    when a particular row is deleted in sheet1, the corresponding row should be automatically deleted from sheet2. column A in both the sheets is ID field which is unique.Please help to solve this problem

  2. #2
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Macro to delete the rows automatically

    in both sheets those unique ID is in the same row or before delete you have to check ID's position in sheet 2 ?

    Best Regards

  3. #3
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro to delete the rows automatically

    I don't think it's possible to trap a row being deleted manually so that code can automatically do what you are asking. The only way really would be to use the code to delete the rows on both sheets.

    Dom
    "May the fleas of a thousand camels infest the crotch of the person who screws up your day and may their arms be too short to scratch..."

    Use code tags when posting your VBA code: [code] Your code here [/code]

    Remember, saying thanks only takes a second or two. Click the little star to give some Rep if you think an answer deserves it.

  4. #4
    Registered User
    Join Date
    06-08-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Macro to delete the rows automatically

    the unique id in both the sheets is in different rows but they are in column A

  5. #5
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Cool Re: Macro to delete the rows automatically

    I hope solution for your problem is made - check attached file

    @Domski - never say never ;-)

    Best Regards
    Last edited by MaczaQ; 06-09-2011 at 07:10 AM.

  6. #6
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro to delete the rows automatically

    Good thinking although your workbook open event will fall over as Me.UsedRange is not valid. You would also need to trap for multiple rows being deleted.

    Dom

  7. #7
    Registered User
    Join Date
    06-08-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Macro to delete the rows automatically

    hi Maczaq...appreciate for your help..but it is throwing some error in Usedrange when the sheet is opened..can you please see to it

  8. #8
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Macro to delete the rows automatically

    correct file attached

    error is solved
    multiply row delete now is available too (thanks Domski for info)

    Best Regards
    Attached Files Attached Files

  9. #9
    Registered User
    Join Date
    06-08-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    14

    Re: Macro to delete the rows automatically

    thanks a lot...can you please tell me how to import this code so that it works perfectly

  10. #10
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Macro to delete the rows automatically

    hi

    Press ALT+F11 in your document (VBA editor should appear)
    drop menu View -> Project Explorer (make sure it is open, should be on the left side)

    click twice on Sheet1 and paste there a code:
    Please Login or Register  to view this content.
    Then press twice on ThisWorkbook and past following code
    Please Login or Register  to view this content.
    Consider to mark this thread as solved and if you are satisfacted as well please click on my reputation's add button

    Best Regards

  11. #11
    Forum Expert Domski's Avatar
    Join Date
    12-14-2009
    Location
    A galaxy far, far away
    MS-Off Ver
    Darth Office 2010
    Posts
    3,950

    Re: Macro to delete the rows automatically

    Hi,

    I know I'm being picky and would have a go myself if I didn't have so much on today but I'm not sure that will work with multiple rows, especially if the user were to select more then one that were non-contiguous.

    Dom

  12. #12
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Macro to delete the rows automatically

    You have right Domski - provided solution works fine only for one deleted row or for selected rows (row by row)

    I will think about update to catch that

    Thanks for your ideas
    Best Regards

  13. #13
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Thumbs up Re: Macro to delete the rows automatically

    Hello All,

    I update the script, now it works for non-contiguous selections.

    I hope no more bugs

    Best Regards
    MaczaQ
    Attached Files Attached Files

  14. #14
    Registered User
    Join Date
    06-08-2011
    Location
    India
    MS-Off Ver
    Excel 2007
    Posts
    14

    Thumbs up Re: Macro to delete the rows automatically

    hi Maczaq..Thanks a lot for your help..appreciate your efforts to solve the issue...

  15. #15
    Valued Forum Contributor MaczaQ's Avatar
    Join Date
    06-03-2011
    Location
    Poland
    MS-Off Ver
    Excel 2003 / XP
    Posts
    510

    Re: Macro to delete the rows automatically

    hi mohan308

    I see You have satisfaction and so have I.

    Please consider to mark this thread as SOLVED and if you want click on add button to add me reputations points

    Best Regards

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

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