Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default delete rows that dont match values in named range

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".
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default delete rows that dont match values in named range


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" wrote in message
...
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".


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default delete rows that dont match values in named range

getting debug for "type mismatch" error on the following line...

If Cells(rn, "B").Value < Text Then
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default delete rows that dont match values in named range

what values are in variables rn and Text ?

"J.W. Aldridge" wrote in message
...
getting debug for "type mismatch" error on the following line...

If Cells(rn, "B").Value < Text Then


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default delete rows that dont match values in named range

4 letter abbreviations for names.


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,049
Default delete rows that dont match values in named range

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" wrote in message
...
what values are in variables rn and Text ?

"J.W. Aldridge" wrote in message
...
getting debug for "type mismatch" error on the following line...

If Cells(rn, "B").Value < Text Then



  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default delete rows that dont match values in named range

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
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default delete rows that dont match values in named range

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" wrote in message
...
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".


  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 425
Default delete rows that dont match values in named range

tried...

Type mismatch... This portion was highlighted.

If .Cells(X, "B").Value < Application.Names("IDS"). _
RefersToRange Then
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 rows that do not match values in dynamic range. Zebrahead Excel Programming 2 March 13th 07 06:27 PM
Named range scope question (using application.match) Keith Excel Programming 2 February 1st 07 09:42 PM
Locking a couple rows so when you do a delete shift row they dont palukagoat Excel Discussion (Misc queries) 3 March 22nd 05 05:25 PM
how do i delete the extra empty rows and columns that i dont need. lindaY Excel Discussion (Misc queries) 3 March 20th 05 03:48 PM
Delete Rows if Certain Values are listed in a Range Name John Excel Programming 6 June 27th 04 10:59 PM


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