PC Review


Reply
Thread Tools Rate Thread

Delete rows if value from cell is not in list

 
 
bony_tony
Guest
Posts: n/a
 
      1st May 2007
Hi,
I have a piece of code which deletes certain rows if an invoice number
is not on a list on another sheet.
I currently have to do this in 2 parts.

1. Insert a column next to the number I am looking up, and insert an
if statement that returns a 1 if the value is not in my other sheet.
Formula;
Range("D1100.FormulaR1C1 = "=IF(ISERROR(VLOOKUP(RC[-1],'All
Invoices'!C[-1],1,0)),1,"""")"

2. Select all the rows containing a 1, and delete them;
firstRowFound = True
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 6 To lastRow
If Range("D" & i) = 1 Then
If firstRowFound = True Then
Rows(i).Select
firstRowFound = False
Else
Union(Selection, Rows(i)).Select
End If
End If
Next i
Selection.Delete Shift:=xlShiftUp

This works ok.
But I want to know if I could select all the rows without have to
enter a new column, and the vlookup function.
Is there some sort of vlookup VBA statement that I can use, which will
have to same effect as vlookup??

Any help would be appreciated.
Thanks
Tony

 
Reply With Quote
 
 
 
 
Bob Phillips
Guest
Posts: n/a
 
      1st May 2007
firstRowFound = True
lastRow = Cells(Rows.Count, "A").End(xlUp).Row
For i = 6 To lastRow
If Not Iserror Application.Match(Range("D" & i), _
Worksheets('All Invoices').Columns(4),0)) Then
If firstRowFound = True Then
Rows(i).Select
firstRowFound = False
Else
Union(Selection, Rows(i)).Select
End If
End If
Next i
Selection.Delete Shift:=xlShiftUp


--
HTH

Bob

(there's no email, no snail mail, but somewhere should be gmail in my addy)

"bony_tony" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi,
> I have a piece of code which deletes certain rows if an invoice number
> is not on a list on another sheet.
> I currently have to do this in 2 parts.
>
> 1. Insert a column next to the number I am looking up, and insert an
> if statement that returns a 1 if the value is not in my other sheet.
> Formula;
> Range("D1100.FormulaR1C1 = "=IF(ISERROR(VLOOKUP(RC[-1],'All
> Invoices'!C[-1],1,0)),1,"""")"
>
> 2. Select all the rows containing a 1, and delete them;
> firstRowFound = True
> lastRow = Cells(Rows.Count, "A").End(xlUp).Row
> For i = 6 To lastRow
> If Range("D" & i) = 1 Then
> If firstRowFound = True Then
> Rows(i).Select
> firstRowFound = False
> Else
> Union(Selection, Rows(i)).Select
> End If
> End If
> Next i
> Selection.Delete Shift:=xlShiftUp
>
> This works ok.
> But I want to know if I could select all the rows without have to
> enter a new column, and the vlookup function.
> Is there some sort of vlookup VBA statement that I can use, which will
> have to same effect as vlookup??
>
> Any help would be appreciated.
> Thanks
> Tony
>



 
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 Rows if any cell in Column H is blank but do not Delete Fir =?Utf-8?B?bWFuZmFyZWVk?= Microsoft Excel Programming 4 28th Sep 2007 05:20 PM
Delete rows if value from cell is not in list Options bony_tony Microsoft Excel Programming 1 3rd May 2007 08:12 AM
do not delete rows in a list. =?Utf-8?B?c3RldmVu?= Microsoft Excel Programming 1 29th Mar 2007 05:15 PM
Delete a list of rows John Fevens Microsoft Excel Programming 3 18th Jun 2004 01:11 AM
Delete Rows below a certain cell Julie Microsoft Excel Programming 7 29th Oct 2003 06:40 PM


Features
 

Advertising
 

Newsgroups
 


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