#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default Macro-pawan

I have 2 sheets in same .xls file. In second sheet-column A, I have list of
some values, say 100 values. In sheet 1-column B, I have list of some 2000
values. Values of sheet 2-columnA are present in sheet1-columnB. Multiple
instances are also there. I want to find all these values in sheet1-columnB
AND OTHER ROWS OF SHEET1 (which doesn't contain values from sheet2) ARE TO BE
DELETED. How can we write macro for this?
Thank you in advance.
-Pawan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 923
Default Macro-pawan

One method follows, it determines length of each data set and reads sheet 1
col B from last to first row and deletes the row if it does not find the
value on sheet 2 column 1.

Sub dedupe()
Application.ScreenUpdating = False
Dim sh1 As Worksheet, sh2 As Worksheet
Dim xlr1 As Long, xlr2 As Long, xr1 As Long, xr2 As Long, xNF As Boolean
Set sh1 = Worksheets("Sheet1")
Set sh2 = Worksheets("Sheet2")

xlr1 = sh1.Cells(Rows.Count, 2).End(xlUp).Row
xlr2 = sh2.Cells(Rows.Count, 1).End(xlUp).Row

For xr1 = xlr1 To 1 Step -1
xNF = True
For xr2 = 1 To xlr2
If sh1.Cells(xr1, 2) = sh2.Cells(xr2, 1) Then
xNF = False
Exit For
End If
Next
If xNF Then Rows(xr1).Delete Shift:=xlUp

Next
Application.ScreenUpdating = True
End Sub


--
Cheers
Nigel



"Pawan" wrote in message
...
I have 2 sheets in same .xls file. In second sheet-column A, I have list

of
some values, say 100 values. In sheet 1-column B, I have list of some 2000
values. Values of sheet 2-columnA are present in sheet1-columnB. Multiple
instances are also there. I want to find all these values in

sheet1-columnB
AND OTHER ROWS OF SHEET1 (which doesn't contain values from sheet2) ARE TO

BE
DELETED. How can we write macro for this?
Thank you in advance.
-Pawan



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Hyperlink-Pawan Pawan New Users to Excel 2 August 4th 05 07:14 AM
macro to paste data in alternate cells-pawan Pawan Excel Programming 7 June 21st 05 11:25 PM
Macro to find text in all worksheets -pawan Pawan Excel Programming 3 June 21st 05 02:31 PM
how to attach macros to excel permanently - pawan Pawan Excel Programming 4 June 21st 05 10:01 AM
Start Macro / Stop Macro / Restart Macro Pete[_13_] Excel Programming 2 November 21st 03 05:04 PM


All times are GMT +1. The time now is 09:46 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"