Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default delete dupes in one of two sheets

Two SS class attendance sheets. Sheet 2 contains names of JrHi, Sheet 1
contains names of grade school students.
Need to delete names of students in Sheet 1 that show up in Sheet 2

Gordy99
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,073
Default delete dupes in one of two sheets

Gordy99 wrote:
Two SS class attendance sheets. Sheet 2 contains names of JrHi, Sheet 1
contains names of grade school students.
Need to delete names of students in Sheet 1 that show up in Sheet 2

Gordy99


Hi Gordy,

Try this macro out on a backup copy of your data.

Student names that appear in column A (starting in row 2, assuming row
1 is a heading)
of Sheet1 and Sheet2 are deleted from Sheet1. The entire row is deleted
and rows below are shifted up.

Public Sub DeleteStudents()
Application.ScreenUpdating = False
'Change the value of the constant HeadingRows to suit
'your needs
Const HeadingRows As Long = 1
Dim lLastRow1 As Long
Dim lLastRow2 As Long
Dim rngNames2 As Range
Dim lRows1 As Long
Dim rngCell2 As Range
lLastRow1 = Sheet1.Range("A" & _
Sheet1.Range("A:A").Rows.Count).End(xlUp).Row
lLastRow2 = Sheet2.Range("A" & _
Sheet2.Range("A:A").Rows.Count).End(xlUp).Row
Set rngNames2 = Sheet2.Range(Sheet2.Cells(HeadingRows + 1, 1), _
Sheet2.Cells(lLastRow2, 1))
For lRows1 = lLastRow1 To HeadingRows + 1 Step -1
For Each rngCell2 In rngNames2
If Sheet1.Cells(lRows1, 1).Value = _
rngCell2.Value Then
Sheet1.Cells(lRows1, 1).EntireRow.Delete _
shift:=xlUp
Exit For
End If
Next rngCell2
Next lRows1
End Sub

If the number of rows taken up by column headings is greater than 1
then just change the value of the constant HeadingRows.

Ken Johnson

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 13
Default delete dupes in one of two sheets



"Ken Johnson" wrote:

Gordy99 wrote:
Two SS class attendance sheets. Sheet 2 contains names of JrHi, Sheet 1
contains names of grade school students.
Need to delete names of students in Sheet 1 that show up in Sheet 2

Gordy99

Thanks. I'll see if I can make it work. It looks like it should. I'll post a
thankyou later.


Hi Gordy,

Try this macro out on a backup copy of your data.

Student names that appear in column A (starting in row 2, assuming row
1 is a heading)
of Sheet1 and Sheet2 are deleted from Sheet1. The entire row is deleted
and rows below are shifted up.

Public Sub DeleteStudents()
Application.ScreenUpdating = False
'Change the value of the constant HeadingRows to suit
'your needs
Const HeadingRows As Long = 1
Dim lLastRow1 As Long
Dim lLastRow2 As Long
Dim rngNames2 As Range
Dim lRows1 As Long
Dim rngCell2 As Range
lLastRow1 = Sheet1.Range("A" & _
Sheet1.Range("A:A").Rows.Count).End(xlUp).Row
lLastRow2 = Sheet2.Range("A" & _
Sheet2.Range("A:A").Rows.Count).End(xlUp).Row
Set rngNames2 = Sheet2.Range(Sheet2.Cells(HeadingRows + 1, 1), _
Sheet2.Cells(lLastRow2, 1))
For lRows1 = lLastRow1 To HeadingRows + 1 Step -1
For Each rngCell2 In rngNames2
If Sheet1.Cells(lRows1, 1).Value = _
rngCell2.Value Then
Sheet1.Cells(lRows1, 1).EntireRow.Delete _
shift:=xlUp
Exit For
End If
Next rngCell2
Next lRows1
End Sub

If the number of rows taken up by column headings is greater than 1
then just change the value of the constant HeadingRows.

Ken Johnson


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
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 0 June 21st 05 05:16 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:53 PM
Macro to delete sheets and saves remaining file does not properly delete module pherrero Excel Programming 0 June 21st 05 04:38 PM
Macro to delete sheets and saves remaining file does not properly delete module bhawane Excel Programming 0 June 21st 05 04:20 PM
delete dupes in column BigRog Excel Programming 3 March 6th 04 06:13 AM


All times are GMT +1. The time now is 01:20 PM.

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

About Us

"It's about Microsoft Excel"