LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 141
Default Delete Rows if Certain Values are listed in a Range Name

I have the following code which endeavours to delete a Row if the value in
Sales Mix, Column C is within a Dynamic Range Name i.e.
"Products_Not_Required". However it is not working for me and instead is
deleting all my Data in Sales Mix.

The following is the code I am using

Sub DeleteProductsNotRequired()

Application.ScreenUpdating = False

With Application
.Calculation = xlManual
.MaxChange = 0.001
End With

Dim rng As Range
Dim CriteriaRng As Range


Sheets("Sales Mix").Select
With ActiveSheet
'Set the AdvancedFilter range
'C1 is the header cell
Set rng = .Range("C1:C" & .Range("C" & Rows.Count).End(xlUp).Row)

With Sheets("Master")
'Set the CriteriaRange range
'A1 must have the same cell.value(Header) as in C1 in the
ActiveSheet
Set CriteriaRng = Range("Products_Not_Required")
End With

'Filter the range
rng.AdvancedFilter Action:=xlFilterInPlace, _
CriteriaRange:=CriteriaRng, Unique:=False

'Set the delete range
On Error Resume Next
Set rng = rng.Offset(1, 0).Resize(Rows.Count - 1, 1) _
.SpecialCells(xlCellTypeVisible)

'Delete visible cells
rng.EntireRow.Delete

'Show all the data
.ShowAllData
On Error GoTo 0

Application.Goto .Range("A1"), True
End With

With Application
.Calculation = xlAutomatic
.MaxChange = 0.001
End With
ActiveWorkbook.PrecisionAsDisplayed = False
Application.ScreenUpdating = True

End Sub


The Range Name I am using the following dynamic formula to define the range

=OFFSET(Master!$A$466,0,0,COUNTA(Master!$A:$A),1)


 
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
How to Delete empty rows in excel in b/w rows with values Dennis Excel Worksheet Functions 3 August 28th 07 04:15 PM
Delete Rows where there are #N/A Values FIRSTROUNDKO via OfficeKB.com Excel Worksheet Functions 3 August 3rd 06 04:03 PM
Sum Column Entries that fall within Date Range Listed In Rows Ben Excel Worksheet Functions 4 July 10th 06 05:43 PM
Delete rows listed less than 8 times??? anilos81 Excel Worksheet Functions 10 November 10th 05 04:29 PM
Deleting Range name's listed in the range address box. Satnam Patel Excel Discussion (Misc queries) 4 May 5th 05 01:42 PM


All times are GMT +1. The time now is 03:56 AM.

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"