Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 177
Default Delete Rows in Worksheet2 that Match Criteria in Worksheet1!A1:A20

I have a macro put together by Ron de Bruin a fewmonths ago... wondering how
I can modify it so that it will delete rows in worksheet2 if ColB in
Worksheet2 contain values referenced in Worksheet1!A1:A200.

In otherwords, how can I modify the line DeleteValue = "*Total*" to
make this work?

thanks very much!



Sub Delete_Row_Multiple_Criteria_with_Autofilter()
Dim DeleteValue As String
Dim rng As Range

DeleteValue = "*Total*"
With ActiveSheet
.Range("A1:A1000").AutoFilter Field:=1, Criteria1:=DeleteValue
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete

End With
.AutoFilterMode = False
End With
End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,123
Default Delete Rows in Worksheet2 that Match Criteria in Worksheet1!A1:A20

Hi Steve

You can loop through the column in Worksheet2 and test it like this

with worksheet2 active and the list in Sheets("Sheet1").Range("A1:A200") try this

Sub Example3()
Dim Lrow As Long
Dim CalcMode As Long
Dim ViewMode As Long
Dim StartRow As Long
Dim EndRow As Long

With Application
CalcMode = .Calculation
.Calculation = xlCalculationManual
.ScreenUpdating = False
End With

ViewMode = ActiveWindow.View
ActiveWindow.View = xlNormalView

With ActiveSheet
.DisplayPageBreaks = False
StartRow = 1
EndRow = .Cells(.Rows.Count, "B").End(xlUp).Row

For Lrow = EndRow To StartRow Step -1

If IsError(.Cells(Lrow, "B").Value) Then
'Do nothing, This avoid a error if there is a error in the cell

ElseIf Not IsError(Application.Match(.Cells(Lrow, "B").Value, _
Sheets("Sheet1").Range("A1:A200"), 0)) Then .Rows(Lrow).Delete

End If
Next
End With

ActiveWindow.View = ViewMode
With Application
.ScreenUpdating = True
.Calculation = CalcMode
End With

End Sub





--
Regards Ron de Bruin
http://www.rondebruin.nl


"SteveC" wrote in message ...
I have a macro put together by Ron de Bruin a fewmonths ago... wondering how
I can modify it so that it will delete rows in worksheet2 if ColB in
Worksheet2 contain values referenced in Worksheet1!A1:A200.

In otherwords, how can I modify the line DeleteValue = "*Total*" to
make this work?

thanks very much!



Sub Delete_Row_Multiple_Criteria_with_Autofilter()
Dim DeleteValue As String
Dim rng As Range

DeleteValue = "*Total*"
With ActiveSheet
.Range("A1:A1000").AutoFilter Field:=1, Criteria1:=DeleteValue
With ActiveSheet.AutoFilter.Range
On Error Resume Next
Set rng = .Offset(1, 0).Resize(.Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng Is Nothing Then rng.EntireRow.Delete

End With
.AutoFilterMode = False
End With
End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 177
Default Delete Rows in Worksheet2 that Match Criteria in Worksheet1!A1

run, thanks for posting this... a big help... Stevec
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 177
Default Delete Rows in Worksheet2 that Match Criteria in Worksheet1!A1

Ron, I thought this same macro could be used to copy formatting from a
matching cell, and to apply that formatting to a row as, instead of deleting
a row.. if you have an interest, could you take a look at this: thanks for
your help...

http://www.microsoft.com/office/comm...5-5909440027f4
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
Copy worksheet1 to worksheet2, keep cell format eg cell size slocookie Excel Discussion (Misc queries) 2 January 8th 10 11:24 AM
How do I make worksheet2 = to worksheet1? otulp78 Excel Discussion (Misc queries) 2 January 4th 09 02:16 AM
Copy Data from Worksheet1 to Worksheet2 IF Worksheet1 Column D = Y jeannie v Excel Worksheet Functions 7 January 25th 08 01:04 PM
copy a string from worksheet1 at row a, column a to worksheet2 row a, column a trammy Excel Programming 1 May 12th 06 07:00 PM
columns on worksheet2 don't sort with worksheet1 PatAlexander Excel Worksheet Functions 1 April 13th 06 02:24 PM


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