Delete rows if match between xlsx files

Crocdundee

Board Regular
Joined
May 10, 2010
Messages
174
Office Version
  1. 2013
Platform
  1. Windows
Purpose: delete a row in W2b.xlsx file if a match is not found in utab.slsx file
colums to match is A:A IN W2B.XLSX AND A:A IN UTAB.SLSX

NOTE: In the last column (6) there ia a row missing which is row 7

I have been trying match to no avail, and I am now not so sure this is the way to go.

Help is always appreciated from the experts
Thanks

using office 2007

w2b.xlsx file

40703ROCK0101 09/06/11 ROCKHAMPTON 01 01
40703ROCK0102 09/06/11 ROCKHAMPTON 01 02
40703ROCK0103 09/06/11 ROCKHAMPTON 01 03
40703ROCK0104 09/06/11 ROCKHAMPTON 01 04
40703ROCK0105 09/06/11 ROCKHAMPTON 01 05
40703ROCK0106 09/06/11 ROCKHAMPTON 01 06
40703ROCK0107 09/06/11 ROCKHAMPTON 01 07
40703ROCK0108 09/06/11 ROCKHAMPTON 01 08
40703ROCK0109 09/06/11 ROCKHAMPTON 01 09
40703ROCK0110 09/06/11 ROCKHAMPTON 01 10
40703ROCK0111 09/06/11 ROCKHAMPTON 01 11
40703ROCK0112 09/06/11 ROCKHAMPTON 01 12


utab.slsx

40703Rock0101 09/06/11 Rockhampton 01 01
40703Rock0102 09/06/11 Rockhampton 01 02
40703Rock0103 09/06/11 Rockhampton 01 03
40703Rock0104 09/06/11 Rockhampton 01 04
40703Rock0105 09/06/11 Rockhampton 01 05
40703Rock0106 09/06/11 Rockhampton 01 06
40703Rock0108 09/06/11 Rockhampton 01 08
40703Rock0109 09/06/11 Rockhampton 01 09
40703Rock0110 09/06/11 Rockhampton 01 10
40703Rock0111 09/06/11 Rockhampton 01 11
40703Rock0112 09/06/11 Rockhampton 01 12
------------------------------------------------------
Help here will be appreciated
Graham
 

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.
Assuming your data starts from Row 2..

I have not tested this code.
Code:
Option Explicit
Sub kpark91()
 
    Application.ScreenUpdating = False
    Application.DisplayAlerts = False
 
    Dim sCount As Double, dCount As Double, sLR As Double, dLR As Double
    Dim sWS As Worksheet, dWS As Worksheet
    dCount = 2
    sCount = 2
    Set dWS = Workbooks("w2b.xlsx")
    Set sWS = Workbooks("utab.xlsx")
    dLR = dWS.Range("A" & Rows.Count).End(xlUp).Row
    sLR = sWS.Range("A" & Rows.Count).End(xlUp).Row
 
    Do While dCount <= dLR
        sCount = 2
        Do While sCount <= sLR
            If sWS.Range("A" & sCount).Value = dWS.Range("A" & dCount).Value Then
                GoTo Continue
            End If
            sCount = sCount + 1
        Loop
        dWS.Range("A" & dCount).EntireRow.Delete
Continue:
        dCount = dCount + 1
    Loop
 
    Application.ScreenUpdating = True
    Application.DisplayAlerts = True
 
Upvote 0
Thanks for the reply.
opened both workbooks
Created a module and pasted the code
and ran the code.
Get this message

Run-Time Error '9':
Subscript out of range

Always stops on
Set dWS = Workbooks("w2b.xlsx")
any Ideas ????
Regards
Graham
 
Upvote 0

Forum statistics

Threads
1,224,586
Messages
6,179,719
Members
452,939
Latest member
WCrawford

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top