PC Review


Reply
Thread Tools Rate Thread

Delete Entire row if value don’t match

 
 
K
Guest
Posts: n/a
 
      13th Nov 2009
Hi all, I got list in Range("A2:A10") of sheet 1 like see below

A………col
LC1
X2Y
GFS
TLL
FST
NWM
ZRS
TWW
UIS

I want macro to check in column A of sheet 2 the values of Range
("A2:A10") of sheet 1 and if any value in column A of sheet 2 don’t
match with the values of sheet 1 then macro should delete entire row
in sheet 2
Please can any friend can help
 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      13th Nov 2009
with Sheets("Sheet2")
LastRow = .Range("A" & Rows.Count).end(xlup).Row
RowCount = LastRow
Do while RowCount >= 1
Data = .Range("A" & Rowcount)
set c = Sheets("Sheet1").Columns("A").find(what:=Data, _
lookin:=xlvalues,lookat:=xlwhole)
if c is nothing then
c.entirerow.delete
end if
RowCount = RowCount - 1
loop
end with

"K" wrote:

> Hi all, I got list in Range("A2:A10") of sheet 1 like see below
>
> A………col
> LC1
> X2Y
> GFS
> TLL
> FST
> NWM
> ZRS
> TWW
> UIS
>
> I want macro to check in column A of sheet 2 the values of Range
> ("A2:A10") of sheet 1 and if any value in column A of sheet 2 don’t
> match with the values of sheet 1 then macro should delete entire row
> in sheet 2
> Please can any friend can help
> .
>

 
Reply With Quote
 
Aussie Bob C
Guest
Posts: n/a
 
      13th Nov 2009
Hi Joel

I tried your code on a test Sheet1 & Sheet2.

It loops through ok but stops on the line c.EntireRow.Delete when it finds a
value not on both sheets.

--
Thank you

Aussie Bob C
Little cost to carry knowledge with you.
Win XP P3 Office 2007 on Mini Mac using VMware.


"Joel" wrote:

> with Sheets("Sheet2")
> LastRow = .Range("A" & Rows.Count).end(xlup).Row
> RowCount = LastRow
> Do while RowCount >= 1
> Data = .Range("A" & Rowcount)
> set c = Sheets("Sheet1").Columns("A").find(what:=Data, _
> lookin:=xlvalues,lookat:=xlwhole)
> if c is nothing then
> c.entirerow.delete
> end if
> RowCount = RowCount - 1
> loop
> end with
>
> "K" wrote:
>
> > Hi all, I got list in Range("A2:A10") of sheet 1 like see below
> >
> > A………col
> > LC1
> > X2Y
> > GFS
> > TLL
> > FST
> > NWM
> > ZRS
> > TWW
> > UIS
> >
> > I want macro to check in column A of sheet 2 the values of Range
> > ("A2:A10") of sheet 1 and if any value in column A of sheet 2 don’t
> > match with the values of sheet 1 then macro should delete entire row
> > in sheet 2
> > Please can any friend can help
> > .
> >

 
Reply With Quote
 
Joel
Guest
Posts: n/a
 
      13th Nov 2009
I was deleting from the wrong sheet.

from
c.entirerow.delete
to
..Rows(RowCount).Delete



"Aussie Bob C" wrote:

> Hi Joel
>
> I tried your code on a test Sheet1 & Sheet2.
>
> It loops through ok but stops on the line c.EntireRow.Delete when it finds a
> value not on both sheets.
>
> --
> Thank you
>
> Aussie Bob C
> Little cost to carry knowledge with you.
> Win XP P3 Office 2007 on Mini Mac using VMware.
>
>
> "Joel" wrote:
>
> > with Sheets("Sheet2")
> > LastRow = .Range("A" & Rows.Count).end(xlup).Row
> > RowCount = LastRow
> > Do while RowCount >= 1
> > Data = .Range("A" & Rowcount)
> > set c = Sheets("Sheet1").Columns("A").find(what:=Data, _
> > lookin:=xlvalues,lookat:=xlwhole)
> > if c is nothing then
> > c.entirerow.delete
> > end if
> > RowCount = RowCount - 1
> > loop
> > end with
> >
> > "K" wrote:
> >
> > > Hi all, I got list in Range("A2:A10") of sheet 1 like see below
> > >
> > > A………col
> > > LC1
> > > X2Y
> > > GFS
> > > TLL
> > > FST
> > > NWM
> > > ZRS
> > > TWW
> > > UIS
> > >
> > > I want macro to check in column A of sheet 2 the values of Range
> > > ("A2:A10") of sheet 1 and if any value in column A of sheet 2 don’t
> > > match with the values of sheet 1 then macro should delete entire row
> > > in sheet 2
> > > Please can any friend can help
> > > .
> > >

 
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 cells in Excel 2007 give a pop up: delete entire sheet row? frogman7 Microsoft Excel Discussion 1 15th Jan 2008 08:58 PM
VLookup Not Searching the entire cell for Match =?Utf-8?B?TEFQ?= Microsoft Excel Misc 3 23rd Feb 2007 05:40 PM
Need to delete last value in column but not delete entire row mike.wilson8@comcast.net Microsoft Excel Programming 4 19th Oct 2006 05:26 PM
Deleting entire rows when several cells match Steve Microsoft Excel Discussion 2 1st Dec 2005 11:33 PM
Edit macro to match entire cell contents nis75p06 Microsoft Excel Misc 1 3rd Sep 2005 04:27 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 10:29 PM.