PC Review


Reply
Thread Tools Rate Thread

Copy row when value NOT found?

 
 
Guest
Posts: n/a
 
      15th Mar 2010
Excel 2003. This one has me stumped. Not sure where to start, since I'm
relying on data being *not* found*

I need to read each row in "Feb_Sheet" looking up the value in column H
(known as PTN) in "Jan_Sheet".

If the PTN is NOT FOUND in Jan_Sheet, then
copy the row from "FebruarySheet" to a just add sheet "Feb_New"
End if

Thanks a ton.
 
Reply With Quote
 
 
 
 
Mike H
Guest
Posts: n/a
 
      15th Mar 2010
Hi,

You didn't tell us where to look for the PTN in the FEB_SHEET so I used
column A. Change to suit

Sub stance()
Dim MyRange As Range
Dim CopyRange As Range
Set sht = Sheets("Feb_Sheet")
Set lookuprange = Sheets("Jan_Sheet").Range("A1:A100") 'Change to suit
lastrow = sht.Cells(Cells.Rows.Count, "H").End(xlUp).Row
Set MyRange = sht.Range("H1:H" & lastrow)
For Each c In MyRange
If WorksheetFunction.CountIf(lookuprange, c.Value) = 0 And c.Value <> ""
Then
If CopyRange Is Nothing Then
Set CopyRange = c.EntireRow
Else
Set CopyRange = Union(CopyRange, c.EntireRow)
End If
End If
Next
If Not CopyRange Is Nothing Then
Worksheets.Add(After:=Worksheets("Feb_Sheet")).Name = "Feb_New"
CopyRange.Copy Sheets("Feb_New").Range("A1")
End If
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"< AVG Joe" wrote:

> Excel 2003. This one has me stumped. Not sure where to start, since I'm
> relying on data being *not* found*
>
> I need to read each row in "Feb_Sheet" looking up the value in column H
> (known as PTN) in "Jan_Sheet".
>
> If the PTN is NOT FOUND in Jan_Sheet, then
> copy the row from "FebruarySheet" to a just add sheet "Feb_New"
> End if
>
> Thanks a ton.

 
Reply With Quote
 
Mike H
Guest
Posts: n/a
 
      15th Mar 2010
OOPS,

wrong way round

You didn't tell us where to look for the PTN in the JAN_SHEET so I used
column A. Change to suit

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Mike H" wrote:

> Hi,
>
> You didn't tell us where to look for the PTN in the FEB_SHEET so I used
> column A. Change to suit
>
> Sub stance()
> Dim MyRange As Range
> Dim CopyRange As Range
> Set sht = Sheets("Feb_Sheet")
> Set lookuprange = Sheets("Jan_Sheet").Range("A1:A100") 'Change to suit
> lastrow = sht.Cells(Cells.Rows.Count, "H").End(xlUp).Row
> Set MyRange = sht.Range("H1:H" & lastrow)
> For Each c In MyRange
> If WorksheetFunction.CountIf(lookuprange, c.Value) = 0 And c.Value <> ""
> Then
> If CopyRange Is Nothing Then
> Set CopyRange = c.EntireRow
> Else
> Set CopyRange = Union(CopyRange, c.EntireRow)
> End If
> End If
> Next
> If Not CopyRange Is Nothing Then
> Worksheets.Add(After:=Worksheets("Feb_Sheet")).Name = "Feb_New"
> CopyRange.Copy Sheets("Feb_New").Range("A1")
> End If
> End Sub
> --
> Mike
>
> When competing hypotheses are otherwise equal, adopt the hypothesis that
> introduces the fewest assumptions while still sufficiently answering the
> question.
>
>
> "< AVG Joe" wrote:
>
> > Excel 2003. This one has me stumped. Not sure where to start, since I'm
> > relying on data being *not* found*
> >
> > I need to read each row in "Feb_Sheet" looking up the value in column H
> > (known as PTN) in "Jan_Sheet".
> >
> > If the PTN is NOT FOUND in Jan_Sheet, then
> > copy the row from "FebruarySheet" to a just add sheet "Feb_New"
> > End if
> >
> > Thanks a ton.

 
Reply With Quote
 
Guest
Posts: n/a
 
      17th Mar 2010
Mike,
Thanks for the start. Your right about the "PTN". It is in column H for both
sheets.
It seems "CopyRange" is always nothing. One thing I've noticed is that from
month to month, I never how many rows I'll to work with. Here is the code
after I've played with it some:

Sub stance()

Dim MyRange As Range
Dim CopyRange As Range
Dim lookuprange As Range
Dim sht As Worksheet

Set sht = Sheets("Feb_Sheet")
Set lookuprange = Sheets("Jan_Sheet").Range("H1:H10805") 'Change to suit

lastrow = sht.Cells(Cells.Rows.Count, "H").End(xlUp).Row

Set MyRange = sht.Range("H1:H" & lastrow)
For Each c In MyRange
If WorksheetFunction.CountIf(lookuprange, c.Value) = 0 And c.Value < ""
Then
If CopyRange Is Nothing Then
Set CopyRange = c.EntireRow
Else
Set CopyRange = Union(CopyRange, c.EntireRow)
End If
End If
Next

If Not CopyRange Is Nothing Then
Worksheets.Add(After:=Worksheets("Feb_Sheet")).Name = "Feb_New"
CopyRange.Copy Sheets("Feb_New").Range("A1")
End If

End Sub



"Mike H" wrote:

> OOPS,
>
> wrong way round
>
> You didn't tell us where to look for the PTN in the JAN_SHEET so I used
> column A. Change to suit
>
> --
> Mike
>
> When competing hypotheses are otherwise equal, adopt the hypothesis that
> introduces the fewest assumptions while still sufficiently answering the
> question.
>
>
> "Mike H" wrote:
>
> > Hi,
> >
> > You didn't tell us where to look for the PTN in the FEB_SHEET so I used
> > column A. Change to suit
> >
> > Sub stance()
> > Dim MyRange As Range
> > Dim CopyRange As Range
> > Set sht = Sheets("Feb_Sheet")
> > Set lookuprange = Sheets("Jan_Sheet").Range("A1:A100") 'Change to suit
> > lastrow = sht.Cells(Cells.Rows.Count, "H").End(xlUp).Row
> > Set MyRange = sht.Range("H1:H" & lastrow)
> > For Each c In MyRange
> > If WorksheetFunction.CountIf(lookuprange, c.Value) = 0 And c.Value <> ""
> > Then
> > If CopyRange Is Nothing Then
> > Set CopyRange = c.EntireRow
> > Else
> > Set CopyRange = Union(CopyRange, c.EntireRow)
> > End If
> > End If
> > Next
> > If Not CopyRange Is Nothing Then
> > Worksheets.Add(After:=Worksheets("Feb_Sheet")).Name = "Feb_New"
> > CopyRange.Copy Sheets("Feb_New").Range("A1")
> > End If
> > End Sub
> > --
> > Mike
> >
> > When competing hypotheses are otherwise equal, adopt the hypothesis that
> > introduces the fewest assumptions while still sufficiently answering the
> > question.
> >
> >
> > "< AVG Joe" wrote:
> >
> > > Excel 2003. This one has me stumped. Not sure where to start, since I'm
> > > relying on data being *not* found*
> > >
> > > I need to read each row in "Feb_Sheet" looking up the value in column H
> > > (known as PTN) in "Jan_Sheet".
> > >
> > > If the PTN is NOT FOUND in Jan_Sheet, then
> > > copy the row from "FebruarySheet" to a just add sheet "Feb_New"
> > > End if
> > >
> > > Thanks a ton.

 
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
Excel VBA - How to copy rows found & to cater if no rows found via autofilter kazzy Microsoft Excel Discussion 1 17th Feb 2011 02:10 AM
Copy Cells Found S1L1Y1 Microsoft Excel Misc 2 19th May 2008 05:31 PM
Genuine Advantage found a hot copy =?Utf-8?B?RG9ubnkgQw==?= Windows XP Help 4 21st Mar 2006 03:35 AM
Re: copy until blank found Ron de Bruin Microsoft Excel Misc 15 25th Aug 2004 10:01 AM
Found archive but cannot copy?? Kalevi Microsoft Outlook Discussion 1 27th Nov 2003 03:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:23 AM.