Microsoft Office Forums

Go Back   Microsoft Office Forums > >

Reply
 
Thread Tools Display Modes
  #1  
Old 07-07-2024, 08:37 AM
RRB's Avatar
RRB RRB is offline Deleting values in one file based on another file Windows 11 Deleting values in one file based on another file Office 2021
Susan Flamingo
Deleting values in one file based on another file
 
Join Date: May 2014
Location: The Holy City of Jerusalem
Posts: 297
RRB is on a distinguished road
Default Deleting values in one file based on another file

Hi dear Friends!

Is there an easy way, that even a total-excel-idiot like myself can handle for:

file (or worksheet1) column 1

a1
a2
a3


a4

file (or worksheet2) column 1

a1
a2
a3
a4
a5
a6
a7

Run the function and now file (or worksheet) 2 looks like this:

a5
a6
a7

I tried asking Google and did not see anything I could understand

Thank you and have a good day!

Susan Flamingo
Reply With Quote
  #2  
Old 07-07-2024, 11:16 AM
Logit Logit is offline Deleting values in one file based on another file Windows 10 Deleting values in one file based on another file Office 2007
Expert
 
Join Date: Jan 2017
Posts: 587
Logit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the roughLogit is a jewel in the rough
Default

The following compares Sheet 1 vs Sheet 2 and finds anything in Sheet 1 that was not in Sheet 2.

I believe for your project you'll need to change (in the macro code) Sheet 1 to reflect Sheet 2 .... and Sheet 2 should be changed to Sheet 1.

Code:
Sub compare()
Application.ScreenUpdating = False
    Sheets(3).Activate  'Go to sheet 3
    Cells.Clear         'and clear all previous results
    
    Range("a1").Select  'set cursor at the top
    
    Sheets(1).Activate  'go to sheet 1
    Range("a1").Select  'begin at the top
    
   
    
    Dim search_for As String   'temp variable to hold what we need to look for
    Dim cnt As Integer         'optional counter to find out how many rows we found
    
    Do While ActiveCell.Value <> ""   'repeat the follwoing loop until it reaches a blank row
        
        search_for = ActiveCell.Offset(0, 1).Value   'get a hold of the value in column B
        
        Sheets(2).Activate  'go to sheet(2)
        
        On Error Resume Next   'incase what we search for is not found, no errors will stop the macro
        
        Range("b:b").Find(search_for).Select  'find the value in column B of sheet 2
        
        If Err <> 0 Then   'If the value was not found, Err will not be zero
        
            On Error GoTo 0  'clearing the error code
            
            Sheets(1).Activate   'go back to sheet 1
            
            r = ActiveCell.Row   'get a hold of current row index
            
            Range(r & ":" & r).Select  'select the whole row
            
            cnt = cnt + 1   'increment the counter
            
            Selection.Copy  'copy current selection
            
            Sheets(3).Activate  'go to sheet 3
            
            ActiveCell.PasteSpecial xlPasteAll  'Past the entire row to sheet 3
            
            ActiveCell.Offset(1, 0).Select  'go down one row to prepare for next row.
            
            
        End If
        Sheets(1).Activate   'return to sheet 1
        ActiveCell.Offset(1, 0).Select   'go to the next row
        
    Loop   'repeat
    Application.ScreenUpdating = True
    Application.CutCopyMode = False
    Sheets(3).Activate    'go to sheet 3 to examine findings
    
    
    MsgBox "I have found " & cnt & " rows that did not exist in sheet 2"
    
End Sub
Reply With Quote
  #3  
Old 07-07-2024, 11:53 AM
Alansidman's Avatar
Alansidman Alansidman is offline Deleting values in one file based on another file Windows 11 Deleting values in one file based on another file Office 2021
עַם יִשְׂרָאֵל חַי
 
Join Date: Apr 2019
Location: Steamboat Springs
Posts: 112
Alansidman has a spectacular aura aboutAlansidman has a spectacular aura aboutAlansidman has a spectacular aura about
Default

One more way with Power Query

Code:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    Source2 = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
    MQ = Table.NestedJoin(Source, {"Column1"}, Source2, {"Column1"}, "Table2", JoinKind.RightAnti),
    #"Expanded Table2" = Table.ExpandTableColumn(MQ, "Table2", {"Column1"}, {"Column1.1"}),
    #"Removed Columns" = Table.RemoveColumns(#"Expanded Table2",{"Column1"})

in
    #"Removed Columns"
__________________
Alan עַם יִשְׂרָאֵל חַ Using O365 v2505
Reply With Quote
  #4  
Old 07-07-2024, 10:08 PM
RRB's Avatar
RRB RRB is offline Deleting values in one file based on another file Windows 11 Deleting values in one file based on another file Office 2021
Susan Flamingo
Deleting values in one file based on another file
 
Join Date: May 2014
Location: The Holy City of Jerusalem
Posts: 297
RRB is on a distinguished road
Default To erase

I appreciate your help.

Will this DELETE the values in sheet 2 that are also in sheet 1?

That is what I require. Sorry if I did not make myself clear in OP

Thank you and have a good day!

Susan Flamingo
Reply With Quote
  #5  
Old 07-08-2024, 03:18 AM
Alansidman's Avatar
Alansidman Alansidman is offline Deleting values in one file based on another file Windows 11 Deleting values in one file based on another file Office 2021
עַם יִשְׂרָאֵל חַי
 
Join Date: Apr 2019
Location: Steamboat Springs
Posts: 112
Alansidman has a spectacular aura aboutAlansidman has a spectacular aura aboutAlansidman has a spectacular aura about
Default

If you are referring to the PQ solution, then the answer is yes. that is what you asked to do.
Attached Files
File Type: xlsx PQ Join2Tables.xlsx (20.1 KB, 6 views)
__________________
Alan עַם יִשְׂרָאֵל חַ Using O365 v2505
Reply With Quote
  #6  
Old 07-08-2024, 04:38 AM
RRB's Avatar
RRB RRB is offline Deleting values in one file based on another file Windows 11 Deleting values in one file based on another file Office 2021
Susan Flamingo
Deleting values in one file based on another file
 
Join Date: May 2014
Location: The Holy City of Jerusalem
Posts: 297
RRB is on a distinguished road
Default TY

Thank you so very much for the assistance. I needed an immediate solution, so being the lazy Flamingo that I am I did a conditional format in Google sheets and deleted all the highlighted rows.

Thank you again and have a good day!
Susan Flamingo
Reply With Quote
  #7  
Old 07-09-2024, 03:32 AM
Pecoflyer's Avatar
Pecoflyer Pecoflyer is offline Deleting values in one file based on another file Windows 10 Deleting values in one file based on another file Office 2021
Expert
 
Join Date: Nov 2011
Location: Brussels Belgium
Posts: 2,920
Pecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond reputePecoflyer has a reputation beyond repute
Default

Please mark thread " solved" ( see "thread tools"). Thx
__________________
Using O365 v2503 - Did you know you can thank someone who helped you? Click on the tiny scale in the right upper hand corner of your helper's post
Reply With Quote
Reply



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to hide/delete slides based on keyword in a separate text file based on AND|OR condition? rupd911 PowerPoint 0 02-22-2021 08:22 AM
deleting page numbers in word file John Witmer Word 6 12-29-2016 09:28 PM
Can we define macros in a way to not misworking after deleting, renaming or moving the source file? tesoke Excel Programming 10 11-13-2015 09:30 AM
Macro for deleting all the images in a file researcher_spain Word VBA 0 06-05-2015 08:02 AM
Deleting values in one file based on another file Excel 2010 deleting original file and .tmp msduh Excel 1 04-09-2012 05:36 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 03:51 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft