Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
No Name
 
Posts: n/a
Default Copy row when value NOT found?

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")).Nam e = "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")).Nam e = "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
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 Cells Found S1L1Y1 Excel Discussion (Misc queries) 2 May 19th 08 05:31 PM
Macro to compare then copy if string found Stuart[_3_] Excel Programming 11 April 20th 07 10:25 AM
copy row when matching colums found lancastergeneral[_2_] Excel Programming 3 December 15th 06 11:11 PM
FOUND LOST FILE BUT COPY IS MISSING NITRAM RENRAS Excel Worksheet Functions 0 January 26th 06 08:03 PM
Copy after Autofilter with no rows found Jeff B[_2_] Excel Programming 7 July 27th 05 01:26 PM


All times are GMT +1. The time now is 04:25 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"