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

Dear expert,
Every day, will get a system generated file.
Have a list of names, duties, work .....

Sheet name is called Summary.
I have a sheet name called Work.
Is it possible if the names shown up in sheet "Work" will be retained, the
rest will be removed in sheet "Summary".

Name Type Time Shift Work
1129.HK PT 1 Half
0566.HK PT 2 Full
0395.HK FT, 3 Full
2302.HK PT, 4 Full
0260.HK PT, 5 Full
0757.HK PT, 6 Full
1088.HK PT, 7 Full
1171.HK PT, 1 Half
1393.HK FT, 2 Half
1898.HK PT, 3 Half
0090.HK FT, 5 Half
0735.HK PT, 3 Half
0091.HK PT, 5 Half
0639.HK PT, 2 Half
0712.HK PT, 1 Half

If sheet "work" has names of 1393.hk, 1129.hk, 0091.hk ..... only these 3
rows starting with these names in sheet "Summary" can be retained.
The rest can be deleted (no need) in sheet "Summary" after running the marco
.....

What shown up in sheet "Work" will determine what can be retained in Sheet
"Summary".

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,565
Default Remove unnecessary rows

Give this a try:

Sub scrub()
Dim sh As Worksheet, sh2 As Worksheet
Dim lr As Long, lr2 As Long
Dim rng As Range, rng2 As Range
Set sh = Sheets("Work")
Set sh2 = Sheets("Summary")
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
lr2 = sh2.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A2:A" & lr)
Set rng2 = sh2.Range("A2:A" & lr2)
For c = lr2 To 2 Step -1
If Application.CountIf(rng, sh2.Cells(c, 1).Value) = 0 Then
sh2.Rows(c).Delete
End If
Next
End Sub



"Elton Law" wrote in message
...
Dear expert,
Every day, will get a system generated file.
Have a list of names, duties, work .....

Sheet name is called Summary.
I have a sheet name called Work.
Is it possible if the names shown up in sheet "Work" will be retained, the
rest will be removed in sheet "Summary".

Name Type Time Shift Work
1129.HK PT 1 Half
0566.HK PT 2 Full
0395.HK FT, 3 Full
2302.HK PT, 4 Full
0260.HK PT, 5 Full
0757.HK PT, 6 Full
1088.HK PT, 7 Full
1171.HK PT, 1 Half
1393.HK FT, 2 Half
1898.HK PT, 3 Half
0090.HK FT, 5 Half
0735.HK PT, 3 Half
0091.HK PT, 5 Half
0639.HK PT, 2 Half
0712.HK PT, 1 Half

If sheet "work" has names of 1393.hk, 1129.hk, 0091.hk ..... only these 3
rows starting with these names in sheet "Summary" can be retained.
The rest can be deleted (no need) in sheet "Summary" after running the
marco
....

What shown up in sheet "Work" will determine what can be retained in Sheet
"Summary".



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 173
Default Remove unnecessary rows

Hi friend, it's amazing job. It works. Thanks

"JLGWhiz" wrote:

Give this a try:

Sub scrub()
Dim sh As Worksheet, sh2 As Worksheet
Dim lr As Long, lr2 As Long
Dim rng As Range, rng2 As Range
Set sh = Sheets("Work")
Set sh2 = Sheets("Summary")
lr = sh.Cells(Rows.Count, 1).End(xlUp).Row
lr2 = sh2.Cells(Rows.Count, 1).End(xlUp).Row
Set rng = sh.Range("A2:A" & lr)
Set rng2 = sh2.Range("A2:A" & lr2)
For c = lr2 To 2 Step -1
If Application.CountIf(rng, sh2.Cells(c, 1).Value) = 0 Then
sh2.Rows(c).Delete
End If
Next
End Sub



"Elton Law" wrote in message
...
Dear expert,
Every day, will get a system generated file.
Have a list of names, duties, work .....

Sheet name is called Summary.
I have a sheet name called Work.
Is it possible if the names shown up in sheet "Work" will be retained, the
rest will be removed in sheet "Summary".

Name Type Time Shift Work
1129.HK PT 1 Half
0566.HK PT 2 Full
0395.HK FT, 3 Full
2302.HK PT, 4 Full
0260.HK PT, 5 Full
0757.HK PT, 6 Full
1088.HK PT, 7 Full
1171.HK PT, 1 Half
1393.HK FT, 2 Half
1898.HK PT, 3 Half
0090.HK FT, 5 Half
0735.HK PT, 3 Half
0091.HK PT, 5 Half
0639.HK PT, 2 Half
0712.HK PT, 1 Half

If sheet "work" has names of 1393.hk, 1129.hk, 0091.hk ..... only these 3
rows starting with these names in sheet "Summary" can be retained.
The rest can be deleted (no need) in sheet "Summary" after running the
marco
....

What shown up in sheet "Work" will determine what can be retained in Sheet
"Summary".



.

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
Removing unnecessary rows through macro [email protected] Excel Programming 6 October 14th 08 02:30 PM
Delete Unnecessary Rows Steve Excel Discussion (Misc queries) 1 May 28th 08 01:23 AM
"Add/Remove Rows Code" adds rows on grouped sheets, but won't remove rows. Conan Kelly Excel Programming 1 November 16th 07 10:41 PM
How do I remove unnecessary vertical page break? 1smstewart1 Excel Worksheet Functions 2 November 15th 06 06:09 PM
Code / Add In to remove unnecessary white space Gazza Excel Programming 2 October 24th 05 10:47 PM


All times are GMT +1. The time now is 12:01 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"