Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 169
Default Copying over Rows Once

The code below compares two worksheets which both have 10 columns,
if there are any differences the entire row is copied and pasted to a separate
Worksheet "Changes".
My problem is that if in any row there is e.g 3 changes, the same row is
copied over three times, obviously I want the row to be copied over only once,
how do I adjust this code to do this.
Help is greatly appreciated


k = 6
For i = 1 To 20
For j = 1 To 10
If Worksheets("Jobs").Cells(i, j) <
Worksheets("Jobs").Cells(i, j) Then
Worksheets("Jobs").Cells(i, j).EntireRow.Copy
Destination:=Worksheets("Changes").Cells(k, 1)
k = k + 1
End If
Next j
Next i
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,624
Default Copying over Rows Once

One way:

k = 6
For i = 1 To 20
For j = 1 To 10
If Worksheets("Jobs1").Cells(i, j) < _
Worksheets("Jobs2").Cells(i, j) Then
Worksheets("Jobs1").Cells(i, j).EntireRow.Copy _
Destination:=Worksheets("Changes").Cells(k, 1)
k = k + 1
Exit For
End If
Next j
Next i

In article ,
teresa wrote:

The code below compares two worksheets which both have 10 columns,
if there are any differences the entire row is copied and pasted to a separate
Worksheet "Changes".
My problem is that if in any row there is e.g 3 changes, the same row is
copied over three times, obviously I want the row to be copied over only once,
how do I adjust this code to do this.
Help is greatly appreciated


k = 6
For i = 1 To 20
For j = 1 To 10
If Worksheets("Jobs").Cells(i, j) <
Worksheets("Jobs").Cells(i, j) Then
Worksheets("Jobs").Cells(i, j).EntireRow.Copy
Destination:=Worksheets("Changes").Cells(k, 1)
k = k + 1
End If
Next j
Next i

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,092
Default Copying over Rows Once

First it looks like you are comparing the same cell to itself
{Worksheets("Jobs").Cells(i, j)}. Probably a typo. Check the destination
sheet to see if it already has that value in it...
k = 6
For i = 1 To 20
For j = 1 To 10
If Worksheets("Jobs").Cells(i, j) < _
Worksheets("Jobs").Cells(i, j) And Worksheets("Jobs").Cells(i, j) < _
Worksheets("Changes").Cells(k, 1) Then
Worksheets("Jobs").Cells(i, j).EntireRow.Copy _
Destination:=Worksheets("Changes").Cells(k, 1)
k = k + 1
End If
Next j
Next i


Mike F

"teresa" wrote in message
...
The code below compares two worksheets which both have 10 columns,
if there are any differences the entire row is copied and pasted to a

separate
Worksheet "Changes".
My problem is that if in any row there is e.g 3 changes, the same row is
copied over three times, obviously I want the row to be copied over only

once,
how do I adjust this code to do this.
Help is greatly appreciated


k = 6
For i = 1 To 20
For j = 1 To 10
If Worksheets("Jobs").Cells(i, j) <
Worksheets("Jobs").Cells(i, j) Then
Worksheets("Jobs").Cells(i, j).EntireRow.Copy
Destination:=Worksheets("Changes").Cells(k, 1)
k = k + 1
End If
Next j
Next i



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
Copying & Inserting Rows w/o Affecting other Rows Etc. LRay67 Excel Worksheet Functions 1 October 22nd 08 02:10 AM
Copying multiple rows to other worksheets (but amount of rows varies) - How? David Smithz Excel Discussion (Misc queries) 1 June 18th 06 04:31 PM
Copying Rows when hiding other rows Neutron1871 Excel Worksheet Functions 2 November 3rd 04 11:38 PM
copying rows monica Excel Programming 1 September 10th 04 09:59 AM
copying rows Qwerty Excel Programming 4 October 30th 03 12:49 PM


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