+ Reply to Thread
Results 1 to 8 of 8

Macro to delete rows where value in Col F and exactly the same as value in Col G

  1. #1
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Macro to delete rows where value in Col F and exactly the same as value in Col G

    I have tried to write code to delete those rows where the value in Col F and exactly the same as Col G (see highlighted Items) , but my code is not deleting these rows


    Please Login or Register  to view this content.

    It would be appreciated if someone could amend my code

  2. #2
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Question Re: Macro to delete rows where value in Col F and exactly the same as value in Col G


    You keep the zero values ?!

    Your code fails 'cause you compare only F & G on the same row !
    Last edited by Marc L; 07-20-2023 at 11:58 AM.

  3. #3
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2405 Win 11 Home 64 Bit
    Posts
    23,885

    Re: Macro to delete rows where value in Col F and exactly the same as value in Col G

    Howard
    You need two loops to make this work.
    Please Login or Register  to view this content.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  4. #4
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Arrow Re: Macro to delete rows where value in Col F and exactly the same as value in Col G


    Or with a single loop using the classic MATCH Excel function or VBA Range.Find method as yet demonstrated in OP threads …

  5. #5
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Macro to delete rows where value in Col F and exactly the same as value in Col G

    Hi Marc L


    I need to keep the zero values

  6. #6
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Macro to delete rows where value in Col F and exactly the same as value in Col G

    Hi Alan


    Thanks for your code


    For some unkown reason one of the values that were the same was not deleted being 3004 in Col G


    Kindly test & amend your code

  7. #7
    Forum Expert
    Join Date
    11-24-2013
    Location
    Paris, France
    MS-Off Ver
    Excel 2003 / 2010
    Posts
    9,831

    Cool Try this !


    According to your initial post attachment an Excel basics VBA demonstration for starters :

    PHP Code: 
    Sub Demo1()
        
    Dim R&, V
            R 
    2
        With 
    [A1].CurrentRegion
            Application
    .ScreenUpdating False
        
    While Not IsEmpty(.Cells(R6))
        If .
    Cells(R6) = 0 Then
            R 
    1
        
    Else
            
    Application.Match(.Cells(R6), .Columns(7), 0)
            If 
    IsError(VThen R Else Union(Rows(R), Rows(V)).Delete
        End 
    If
        
    Wend
            Application
    .ScreenUpdating True
        End With
    End Sub 
    ► Do you like it ? ► So thanks to click on bottom left star icon « Add Reputation » !

  8. #8
    Forum Contributor
    Join Date
    07-12-2018
    Location
    South Africa
    MS-Off Ver
    Office 2021
    Posts
    2,725

    Re: Macro to delete rows where value in Col F and exactly the same as value in Col G

    Thanks Marc. Your code works 100%

+ 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. [SOLVED] Macro to Delete blank rows by shifting rows upwards
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 12-22-2022, 05:34 AM
  2. [SOLVED] Macro to Delete Delete headings and 9 rows above from row 15 onwards
    By Howardc1001 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 07-01-2021, 12:06 AM
  3. Replies: 1
    Last Post: 01-07-2019, 10:54 AM
  4. Macro To Find Rows With Duplicates, Compare Cells, And Delete Rows. - Excel
    By Kwame001 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 09-26-2013, 10:41 AM
  5. 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
  6. Replies: 13
    Last Post: 08-23-2011, 11:00 AM
  7. How to make my macro delete rows? It currently hides the rows instead of deleting.
    By Majkataxmk in forum Excel Programming / VBA / Macros
    Replies: 16
    Last Post: 05-20-2010, 01:14 PM

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