+ Reply to Thread
Results 1 to 9 of 9

Compare columns on one sheet to another and delete if negative values found

  1. #1
    Forum Contributor
    Join Date
    11-01-2012
    Location
    NJ
    MS-Off Ver
    Excel 365
    Posts
    109

    Compare columns on one sheet to another and delete if negative values found

    Hello,

    I am trying to create a code to compare Column A and Column B on sheet "Removal of Offsets" to Column J on "GL Activity" - if the string is found I need to compare on sheet "GL Activity" - column F "Account Name", column G "Account Identifier" are the same and Column V - "Base Transaction Amount" to see if there is a negative value for the corresponding entry exists and if all the criteria are met then delete both line as they should net out.

    Example:
    Sheet - Removal of Offsets
    Column A Column B
    IMS_TAXPRP+ IMS_TAXPR+

    Sheet GL Activity
    Column F Column G Column K Column V
    ABC Bank 123456 IMS_TAXPRP+ 276.25
    ABC Bank 123456 IMS_TAXPR+ -276.25

    Both of these entries would be deleted off of the GL Activity Sheet since they offset one another value wise.

    Appreciate any assistance you can give!

    Thanks
    Attached Files Attached Files

  2. #2
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Compare columns on one sheet to another and delete if negative values found

    Never mind, I see that it is more complex than I orginally thought.
    Last edited by JLGWhiz; 09-04-2019 at 03:47 PM.
    Any code provided by me should be tested on a copy or a mock up of your original data before applying it to the original. Some events in VBA cannot be reversed with the undo facility in Excel. If your original post is satisfied, please mark the thread as "Solved". To upload a file, see the banner at top of this page.
    Just when I think I am smart, I learn something new!

  3. #3
    Forum Contributor
    Join Date
    11-01-2012
    Location
    NJ
    MS-Off Ver
    Excel 365
    Posts
    109

    Re: Compare columns on one sheet to another and delete if negative values found

    Appreciate the effort! If you have any ideas, on how to accomplish this, I'd appreciate the help once again! Thanks JLG!

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

    Question

    Hi !

    Can you complete, detail, elaborate all the rules ?

  5. #5
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Compare columns on one sheet to another and delete if negative values found

    Quote Originally Posted by mikey3580 View Post
    Appreciate the effort! If you have any ideas, on how to accomplish this, I'd appreciate the help once again! Thanks JLG!
    Yeah, I am still looking at the layout and trying to come up with an efficient way of making sure that all the credits and debits are matched up. I wrote the other code assuming that there would only be one ledger entry per account, then when I looked and saw it was more like analog journal entries, that code went out the window, so to speak.

  6. #6
    Forum Contributor
    Join Date
    11-01-2012
    Location
    NJ
    MS-Off Ver
    Excel 365
    Posts
    109

    Re: Compare columns on one sheet to another and delete if negative values found

    Thanks Marc!

    Rule 1
    If Column A on sheet "Removal of Offsets" is found in column Column J on sheet "GL Activity" then look column B on sheet "Removal of Offsets" and see if then entry is that is referenced from column A on "Removal of Offsets" exists on in column Column J on sheet "GL Activity" also

    If Rule 1 is met then Rule 2
    Compare on sheet "GL Activity" - column F "Account Name", column G "Account Identifier" are the same for each of the Column A from sheet "Removal of Offsets" and Column B from sheet "Removal of Offsets".

    If Rule 2 is met then Rule 3
    Compare on sheet "GL Activity" - Column V - "Base Transaction Amount" to see if there is a negative value for each of the Column A from sheet "Removal of Offsets" and Column B from sheet "Removal of Offsets"

    Finally - if all the criteria are met then delete both lines

    Example:
    Sheet - "Removal of Offsets"
    Column A Column B
    IMS_TAXPRP+ IMS_TAXPR+

    Sheet "GL Activity"
    Column F Column G Column K Column V
    ABC Bank 123456 IMS_TAXPRP+ 276.25
    ABC Bank 123456 IMS_TAXPR+ -276.25

    Both of these entries would be deleted off of the "GL Activity" Sheet since Column K matches the code from Columns A and B from "Removal of Offsets". Additionally when compared to each other from the "GL Activity" Sheet they have the same Column F, same Column G, and are recipricals of one another in value and offset each other.

    File attached can show you what it is and what it should look like end result.

    Appreciate any assistance you can give!
    Attached Files Attached Files

  7. #7
    Forum Expert JLGWhiz's Avatar
    Join Date
    02-20-2011
    Location
    Florida, USA
    MS-Off Ver
    Windows 10, Excel 2013
    Posts
    2,070

    Re: Compare columns on one sheet to another and delete if negative values found

    This made me use brain cells I haven't used for years, but I think it will now work correctly. It might take a few seconds to run in your actual file if it has a lot of data in the two sheets.

    Please Login or Register  to view this content.

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

    Cool

    A starter demonstration to paste to the GL Activity worksheet module :

    PHP Code: 
    Sub Demo1b()
         
    Dim VC&, WY%(), L&, R&
             
    Sheets("Removal of Offsets").UsedRange.Value2
             C 
    Me.UsedRange.Rows.Count
             W 
    Application.Index(Me.UsedRangeEvaluate("ROW(1:" ")"), [{7,10,22}])
             
    ReDim Y(1 To C0)
        
    With CreateObject("Scripting.Dictionary")
            For 
    2 To UBound(V):  .Item(V(L1)) = V(L2):  Next
            
    For 2 To C 1
                
    If .Exists(W(L2)) And Y(L0) = 0 Then
                        V 
    = .Item(W(L2))
                    For 
    1 To C
                        
    If W(R1) = W(L1) And W(R2) = And W(R3) = -W(L3) And Y(R0) = 0 Then
                            Y
    (L0) = 1
                            Y
    (R0) = 1
                            
    Exit For
                        
    End If
                    
    Next
                End 
    If
            
    Next
               
    .RemoveAll
        End With
        
    If IsNumeric(Application.Match(1Y0)) Then
             Application
    .ScreenUpdating False
             Me
    .UsedRange.Columns(25).Value2 Y
        With Me
    .UsedRange
            
    .Sort [Y1], xlAscendingHeader:=xlYes
            
    .Rows(Application.Match(1, .Columns(25), 0) & ":" C).Clear
            
    .Columns(25).Clear
        End With
             Application
    .ScreenUpdating True
        End 
    If
    End Sub 
    Do you like it ? So thanks to click on bottom left star icon « Add Reputation » !
    Last edited by Marc L; 09-04-2019 at 10:15 PM. Reason: optimization if executed twice …

  9. #9
    Forum Contributor
    Join Date
    11-01-2012
    Location
    NJ
    MS-Off Ver
    Excel 365
    Posts
    109

    Re: Compare columns on one sheet to another and delete if negative values found

    Thank you both! JLGWhiz yours worked exactly like I needed it too! Genius! So appreciative!!

    Marc - thank you as well! Very appreciative of your efforts! Very great stuff!!

+ 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] Look up negative values in Tables, if found copy data in that row to another sheet
    By popcorn7 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 11-23-2018, 01:57 AM
  2. Auto fill Log sheet from Negative values found on another sheet.
    By MrKingisin in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 09-12-2016, 06:41 PM
  3. Need to compare values in 2 Columns & return result for what was found
    By pblobe in forum Excel Formulas & Functions
    Replies: 4
    Last Post: 06-28-2015, 12:57 PM
  4. Use VBA loops to search for a list of values, delete columns they are found in
    By jfgay in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 07-25-2013, 07:58 AM
  5. Compare two sheets and delete row if match found
    By Steinwall in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-13-2011, 03:25 PM
  6. Compare 2 columns delete rows with matching values
    By mattmac in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 02-05-2009, 01:50 PM
  7. Compare two columns and delete founded values
    By Oleg in forum Excel General
    Replies: 0
    Last Post: 09-28-2006, 09:50 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