+ Reply to Thread
Results 1 to 14 of 14

Macro to delete rows based in the comparative of the columns between two sheets

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Thumbs up Macro to delete rows based in the comparative of the columns between two sheets

    Hi Guys,

    I need to create a macro to delete the rows of the Master sheet based on the Report sheet.
    The condition is, if the the number in the column A in the "Master" sheet is not in the first column in the "Report" sheet, the entire row regarding this number in the "Master" sheet should be deleted. Simple as that.

    Any idea?

    You can find the sheet attached below demonstrating that:
    Production example.xlsm

    I appreciate guys!
    Thank you!
    Last edited by ricdamiani; 08-19-2013 at 10:37 PM.

  2. #2
    Forum Guru
    Join Date
    08-15-2004
    Location
    Tokyo, Japan
    MS-Off Ver
    2013 O.365
    Posts
    22,666

    Re: Macro to delete rows based in the comparative of the columns between two sheets

    try
    Sub test()
        Application.ScreenUpdating = False
        With Sheets("master")
            .Columns(1).Insert
            With .Range("b5", .Range("b" & Rows.Count).End(xlUp)).Offset(, -1)
                .Formula = "=isnumber(match(b5,report!a:a,0))"
                .Value = .Value
            End With
            With .Range("a5").CurrentRegion
                .AutoFilter 1, False
                .Offset(1).EntireRow.Delete
                .AutoFilter
            End With
            .Columns(1).Delete
        End With
        Application.ScreenUpdating = True
    End Sub

  3. #3
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to delete rows based in the comparative of the columns between two sheets

    Quote Originally Posted by jindon View Post
    try
    Sub test()
        Application.ScreenUpdating = False
        With Sheets("master")
            .Columns(1).Insert
            With .Range("b5", .Range("b" & Rows.Count).End(xlUp)).Offset(, -1)
                .Formula = "=isnumber(match(b5,report!a:a,0))"
                .Value = .Value
            End With
            With .Range("a5").CurrentRegion
                .AutoFilter 1, False
                .Offset(1).EntireRow.Delete
                .AutoFilter
            End With
            .Columns(1).Delete
        End With
        Application.ScreenUpdating = True
    End Sub
    Hi guys and jindon,

    I need to add one more sheet in the comparison, the sheet tab "orders". So the new condition is (see in bold): if the the number in the column A in the "Master" sheet is not in the first column in the "Report" sheet and in the "Orders" sheet, the entire row regarding this number in the "Master" sheet should be deleted.

    Is that possible?!

    Thanks guys

  4. #4
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to delete rows based in the comparative of the columns between two sheets

    Yes, it is working.
    Thanks jindon

  5. #5
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to delete rows based in the comparative of the columns between two sheets

    UP

    Somebody else can help on that?

  6. #6
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to delete rows based in the comparative of the columns between two sheets

    Hi guys,

    It is really important this macro... just need to update...
    Somebody can help me?

  7. #7
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to delete rows based in the comparative of the columns between two sheets

    Hi everybody,

    Somebody able to help me on that?!

    I really appreciate

  8. #8
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to delete rows based in the comparative of the columns between two sheets

    Up!

    Please somebody give a hand

  9. #9
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to delete rows based in the comparative of the columns between two sheets

    Hi everybody,
    Somebody could help me on this macro?!
    The update looks simple but I am not sure how to do it: if the the number in the column A in the "Master" sheet is not in the first column in the "Report" sheet and in the "Orders" sheet, the entire row regarding this number in the "Master" sheet should be deleted.

    And the code is
    Sub test()
        Application.ScreenUpdating = False
        With Sheets("master")
            .Columns(1).Insert
            With .Range("b5", .Range("b" & Rows.Count).End(xlUp)).Offset(, -1)
                .Formula = "=isnumber(match(b5,report!a:a,0))"
                .Value = .Value
            End With
            With .Range("a5").CurrentRegion
                .AutoFilter 1, False
                .Offset(1).EntireRow.Delete
                .AutoFilter
            End With
            .Columns(1).Delete
        End With
        Application.ScreenUpdating = True
    End Sub

  10. #10
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to delete rows based in the comparative of the columns between two sheets

    Hi everybody,
    Hi Jindon , AB33

    Any solution for this one?!
    Thank you!

  11. #11
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Macro to delete rows based in the comparative of the columns between two sheets

    maybe so
    ...
            With .Range("b5", .Range("b" & Rows.Count).End(xlUp)).Offset(, -1)
                .Formula = "=--AND(ISNUMBER(MATCH(b5,Report!a:a,0)),ISNUMBER(MATCH(b5,Orders!a:a,0)))"
                .Value = .Value
            End With
            With .Range("a5").CurrentRegion
                .AutoFilter 1, 0
                .Offset(1).EntireRow.Delete
                .AutoFilter
            End With
            ...

  12. #12
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to delete rows based in the comparative of the columns between two sheets

    Quote Originally Posted by nilem View Post
    maybe so
    ...
            With .Range("b5", .Range("b" & Rows.Count).End(xlUp)).Offset(, -1)
                .Formula = "=--AND(ISNUMBER(MATCH(b5,Report!a:a,0)),ISNUMBER(MATCH(b5,Orders!a:a,0)))"
                .Value = .Value
            End With
            With .Range("a5").CurrentRegion
                .AutoFilter 1, 0
                .Offset(1).EntireRow.Delete
                .AutoFilter
            End With
            ...
    Hi nilem,
    Thank you for your reply.

    The macro is actually deleting everything, it is clearing the whole master sheet ("Schedule" sheet).
    I attached a sample sheet showing exactly what I mean:
    SAMPLE 19-08.xlsm

    The macro you gave me is in the file. When you run it, it clears everything.

    Any solution for this?!

    I really appreciate

  13. #13
    Forum Expert nilem's Avatar
    Join Date
    10-22-2011
    Location
    Ufa, Russia
    MS-Off Ver
    2013
    Posts
    3,377

    Re: Macro to delete rows based in the comparative of the columns between two sheets

    try it
    .Formula = "=--OR(ISNUMBER(MATCH(B4,'Sap Report'!A:A,0)),ISNUMBER(MATCH(B4,Orders!A:A,0)))"

  14. #14
    Forum Contributor
    Join Date
    07-28-2013
    Location
    Sydney, Australia
    MS-Off Ver
    Office 365
    Posts
    298

    Re: Macro to delete rows based in the comparative of the columns between two sheets

    It is working.
    Thank you

+ 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. Delete rows based on 3 columns
    By nitin1309 in forum Excel Programming / VBA / Macros
    Replies: 10
    Last Post: 06-27-2013, 03:32 PM
  2. Delete rows based off two columns
    By lricci in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-23-2013, 12:37 PM
  3. Compare two columns from diff excel sheets and delete all non matching rows
    By Girija in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 04-24-2013, 11:08 PM
  4. Macro to delete certain columns and delete rows based on time in another column
    By beepbeep27 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 05-12-2012, 11:47 AM
  5. Macro to delete entire rows based values in columns
    By shamade2107 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 03-13-2009, 11:17 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