PC Review


Reply
Thread Tools Rate Thread

delete rows that dont match values in named range

 
 
J.W. Aldridge
Guest
Posts: n/a
 
      20th May 2009
Header row a5:F5.
Data starts at A6..
Based on values starting in column B6 to the bottom, I would like to
delete each row that doesnt match the values in named range "IDS".
 
Reply With Quote
 
 
 
 
Patrick Molloy
Guest
Posts: n/a
 
      20th May 2009

text = range("IDS").value
for rn = range("A6").End(xlDown).Row to 6 step -1
if cells(rn,"B").Value <> text then
rows(rn).Delete
end if
next



"J.W. Aldridge" <(E-Mail Removed)> wrote in message
news:269e5d30-64f0-4fd8-9e76-(E-Mail Removed)...
> Header row a5:F5.
> Data starts at A6..
> Based on values starting in column B6 to the bottom, I would like to
> delete each row that doesnt match the values in named range "IDS".


 
Reply With Quote
 
J.W. Aldridge
Guest
Posts: n/a
 
      20th May 2009
getting debug for "type mismatch" error on the following line...

If Cells(rn, "B").Value <> Text Then
 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      20th May 2009
what values are in variables rn and Text ?

"J.W. Aldridge" <(E-Mail Removed)> wrote in message
news:85575576-1dda-4de0-b560-(E-Mail Removed)...
> getting debug for "type mismatch" error on the following line...
>
> If Cells(rn, "B").Value <> Text Then


 
Reply With Quote
 
J.W. Aldridge
Guest
Posts: n/a
 
      20th May 2009
4 letter abbreviations for names.
 
Reply With Quote
 
Patrick Molloy
Guest
Posts: n/a
 
      20th May 2009
rn should be a row number
use F8 to step through the code and at the line you mention, hover the mouse
over rn and text to see what values they hold

rn is
DIM rn as Long

and its used in the for...next loop


for rn = range("A6").End(xlDown).Row to 6 step -1


"Patrick Molloy" <(E-Mail Removed)> wrote in message
news:37F4AD6D-CFD9-492D-B603-(E-Mail Removed)...
> what values are in variables rn and Text ?
>
> "J.W. Aldridge" <(E-Mail Removed)> wrote in message
> news:85575576-1dda-4de0-b560-(E-Mail Removed)...
>> getting debug for "type mismatch" error on the following line...
>>
>> If Cells(rn, "B").Value <> Text Then

>


 
Reply With Quote
 
J.W. Aldridge
Guest
Posts: n/a
 
      20th May 2009
Hovered over text line and nothing came up.
So, i went back to

Text = Range("IDS").Value

and this showed up.

Text = Range("IDS").Value = <text mismatch>
 
Reply With Quote
 
Rick Rothstein
Guest
Posts: n/a
 
      20th May 2009
Here is a macro for you to try...

Sub DeleteRows()
Dim X As Long
Dim LastRow As Long
With ActiveSheet
LastRow = .Cells(.Rows.Count, "B").End(xlUp).Row
For X = LastRow To 6 Step -1
If .Cells(X, "B").Value <> Application.Names("IDS"). _
RefersToRange Then .Cells(X, "B").EntireRow.Delete
Next
End With
End Sub

As set up, it assumes that the active sheet is the sheet you want to perform
your deletions on. If that will not always be the case, then change this
line...

With ActiveSheet

to this...

With Worksheets("Sheet1")

where you would change Sheet1 to name of the actual sheet you will want to
do the deletions on.

--
Rick (MVP - Excel)


"J.W. Aldridge" <(E-Mail Removed)> wrote in message
news:269e5d30-64f0-4fd8-9e76-(E-Mail Removed)...
> Header row a5:F5.
> Data starts at A6..
> Based on values starting in column B6 to the bottom, I would like to
> delete each row that doesnt match the values in named range "IDS".


 
Reply With Quote
 
J.W. Aldridge
Guest
Posts: n/a
 
      20th May 2009
tried...

Type mismatch... This portion was highlighted.

If .Cells(X, "B").Value <> Application.Names("IDS"). _
RefersToRange Then
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete Named rnage and Add Named Range ryguy7272 Microsoft Excel Programming 5 5th Feb 2010 10:15 AM
How delete rows in named range John Microsoft Excel Programming 5 1st Feb 2009 03:44 AM
copy rows that do not match values in dynamic range. =?Utf-8?B?WmVicmFoZWFk?= Microsoft Excel Programming 2 13th Mar 2007 06:27 PM
Named range scope question (using application.match) Keith Microsoft Excel Programming 2 1st Feb 2007 09:42 PM
Delete Rows if Certain Values are listed in a Range Name John Microsoft Excel Programming 6 27th Jun 2004 10:59 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 07:11 PM.