Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default find and delete rows


Hi,
I got 2 worksheets containing data of students. what i want to do is,
find all the data of worksheet1 in worksheet 2, and delete entire row
containing all the data. e.g.

worksheet 1:
name ID No
NIK ANIS AMIRAH BINTI NIK IZANI 871007145768
NIK HIDAYATUL IZNI BINTI MOHD HATTA 870515105020
NIK IKHWAN HAQIM BIN HANAFI 871106295171
NIK MOHAMAD FAIDHI BIN NIK AZLAN 870206295481
NIK NUR AMALINA BINTI MAT ZAIDAN 870709035606
NIK SAIFUL LIZAM BIN NIK MOKHTAR 880415065315

i want to find all of these students in worksheet 2 and delete them
(entire row).

so any idea how to do that instead of using find & replace 1 by 1? for
info, worksheets 2 containing more than 2000 students data.

thanks.


--
sulie
------------------------------------------------------------------------
sulie's Profile: http://www.excelforum.com/member.php...o&userid=24063
View this thread: http://www.excelforum.com/showthread...hreadid=376980

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default find and delete rows


There is no simple macro solution to your problem. This is because, the
deletions could occur hapzardly anywhere in the data range on Sheet2
hence making a looping step-through a nightmare. I take it that there
is no seqential similiarity in the structure of both lists.

One way around is to copy list on Sheet1 to say columns d and e on
Sheet2 and use a VLOOKUP whksheet function in column F to identify
repeats and non-repeats. In your IF clause, assign "" to non-repeats.
Next run a macro to delete rows with null strings "".

Sub delrows()
For each c in Range("F:F")
If c="" then c.entirerow.delete
end if
next
end if

HTH


--
davidm
------------------------------------------------------------------------
davidm's Profile: http://www.excelforum.com/member.php...o&userid=20645
View this thread: http://www.excelforum.com/showthread...hreadid=376980

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1
Default find and delete rows


Hi Sulie

Supposing the numbers identify the students and supposing that they ar
in column G both on sheet1 and sheet2 the macro below could solve you
problem:

Sub DeleteRowsOnSheet2()
Dim lRow As Long, lMaxRow As Long
Dim vRow As Variant
Dim sht1 As Worksheet, sht2 As Worksheet

Set sht1 = Worksheets(1)
Set sht2 = Worksheets(2)

' make things run faster
Application.ScreenUpdating = False

' thx to david mcritchie <g
lMaxRow = sht1.Cells(Rows.Count, 7).End(xlUp).Row

For lRow = 1 To lMaxRow
' if we have a number on this row in column G
If Not IsEmpty(sht1.Cells(lRow, 7)) Then
' try to find it on sheet 2 in column G
vRow = Application.Match(sht1.Cells(lRow, 7), sht2.Columns(7)
0)
If Not IsError(vRow) Then
' the number is there, so delete the row
sht2.Rows(vRow).Delete
End If
End If
Next lRow

MsgBox "Done!"

Set sht1 = Nothing
Set sht2 = Nothing
End Sub

With kind regards,
Ton Teun

--
Ton
-----------------------------------------------------------------------
TonT's Profile: http://www.officehelp.in/member.php?userid=4
View this thread: http://www.officehelp.in/showthread.php?t=66124
Visit - http://www.officehelp.in/archive/index.php | http://www.officehelp.in/index/index.ph

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
find and delete rows macro clayton ledford Excel Discussion (Misc queries) 4 January 20th 09 03:34 PM
find text and delete rows. John Excel Discussion (Misc queries) 5 December 12th 07 04:25 AM
Find and delete all other rows Murray Excel Discussion (Misc queries) 1 August 7th 07 02:54 AM
Find according to sheet 2, Delete rows in COL A Rubix³ Excel Programming 3 June 24th 04 12:12 AM
Find item and delete rows Joseph[_28_] Excel Programming 1 April 20th 04 06:55 PM


All times are GMT +1. The time now is 02:17 PM.

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"