Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 44
Default Copy entire row to different worksheet

The macro that I am looking for compares column A between 2 different
worksheets(PTR and Reference data). If the Macro finds a match it takes that
row from Reference data worksheet and copies it to the PTR worksheet starting
at column X. There is information from a macro ran before this that
populates PTR. After the initial information I want the information from the
Reference data worksheet to be placed into the PTR worksheet for reporting
purposes.

Example:
Row 6 in PTR and Row 3 in Reference data match(both contain €˜CR239492).
Once the match is found the macro takes all of row 3 from Reference data and
pastes it to Row 6 of PTR starting at column X.
Please do provide me as much assistance as possible

Thanks

-Keith-

  #2   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Copy entire row to different worksheet

You can't paste an entire row (A:IV) into column X:IV. The number of columns
wouldn't match. (Adjust that IV to whatever the last column is in xl2007 if
you're using that.)

But you could paste lots(?) of columns (23) A:W into X:AT (if I counted right).

Option Explicit
Sub testme()

Dim PTRWks As Worksheet
Dim RefWks As Worksheet

Dim PTRRng As Range
Dim RefRng As Range
Dim myCell As Range

Dim res As Variant 'could be an error

Dim HowManyColsToCopy As Long

HowManyColsToCopy = 23

Set PTRWks = Worksheets("PTR")
Set RefWks = Worksheets("Reference data")

With PTRWks
'row 1 of PTR has headers???
Set PTRRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
'remove any existing values in X to ???
.Range("x1").EntireColumn.Resize(, HowManyColsToCopy).ClearContents
End With

With RefWks
Set RefRng = .Range("A:A") 'use the whole column to match
End With

For Each myCell In PTRRng.Cells
If myCell.Value = "" Then
'skip it
Else
res = Application.Match(myCell.Value, RefRng, 0)
If IsError(res) Then
'no match, skip it
Else
'copies the key, too
RefRng(res).Resize(1, HowManyColsToCopy).Copy _
Destination:=PTRWks.Cells(myCell.Row, "X")
End If
End If
Next myCell

End Sub

Kcope8302 wrote:

The macro that I am looking for compares column A between 2 different
worksheets(PTR and Reference data). If the Macro finds a match it takes that
row from Reference data worksheet and copies it to the PTR worksheet starting
at column X. There is information from a macro ran before this that
populates PTR. After the initial information I want the information from the
Reference data worksheet to be placed into the PTR worksheet for reporting
purposes.

Example:
Row 6 in PTR and Row 3 in Reference data match(both contain €˜CR239492).
Once the match is found the macro takes all of row 3 from Reference data and
pastes it to Row 6 of PTR starting at column X.
Please do provide me as much assistance as possible

Thanks

-Keith-


--

Dave Peterson
  #3   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 35,218
Default Copy entire row to different worksheet

ps.

If you're new to macros:

Debra Dalgleish has some notes how to implement macros he
http://www.contextures.com/xlvba01.html

David McRitchie has an intro to macros:
http://www.mvps.org/dmcritchie/excel/getstarted.htm

Ron de Bruin's intro to macros:
http://www.rondebruin.nl/code.htm

(General, Regular and Standard modules all describe the same thing.)

Kcope8302 wrote:

The macro that I am looking for compares column A between 2 different
worksheets(PTR and Reference data). If the Macro finds a match it takes that
row from Reference data worksheet and copies it to the PTR worksheet starting
at column X. There is information from a macro ran before this that
populates PTR. After the initial information I want the information from the
Reference data worksheet to be placed into the PTR worksheet for reporting
purposes.

Example:
Row 6 in PTR and Row 3 in Reference data match(both contain €˜CR239492).
Once the match is found the macro takes all of row 3 from Reference data and
pastes it to Row 6 of PTR starting at column X.
Please do provide me as much assistance as possible

Thanks

-Keith-


--

Dave Peterson
  #4   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 5,441
Default Copy entire row to different worksheet

Keith,

In Cell X6, use a formula like this in X6 of PTR:

=IF(ISERROR(VLOOKUP($A6,'Reference Data'!$A$1:$Z$10000,COLUMN(B1),FALSE)),"",VLOOKUP( $A6,'Reference
Data'!$A$1:$Z$10000,COLUMN(B1),FALSE))

Then copy to the right and down for as many rows and columns as you need. Change the range address
'Reference Data'!$A$1:$Z$10000 to match your data table on reference data...


HTH,
Bernie
MS Excel MVP


"Kcope8302" wrote in message
...
The macro that I am looking for compares column A between 2 different
worksheets(PTR and Reference data). If the Macro finds a match it takes that
row from Reference data worksheet and copies it to the PTR worksheet starting
at column X. There is information from a macro ran before this that
populates PTR. After the initial information I want the information from the
Reference data worksheet to be placed into the PTR worksheet for reporting
purposes.

Example:
Row 6 in PTR and Row 3 in Reference data match(both contain 'CR239492').
Once the match is found the macro takes all of row 3 from Reference data and
pastes it to Row 6 of PTR starting at column X.
Please do provide me as much assistance as possible

Thanks

-Keith-



  #5   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 44
Default Copy entire row to different worksheet

Once a match is found I do not need the whole line from reference data to be
copied to PTR. The information in cells L:O contain the data that is relevant
for my reports. That information can then be pasted starting at cell X in
PTR.

Thanks,

"Dave Peterson" wrote:

You can't paste an entire row (A:IV) into column X:IV. The number of columns
wouldn't match. (Adjust that IV to whatever the last column is in xl2007 if
you're using that.)

But you could paste lots(?) of columns (23) A:W into X:AT (if I counted right).

Option Explicit
Sub testme()

Dim PTRWks As Worksheet
Dim RefWks As Worksheet

Dim PTRRng As Range
Dim RefRng As Range
Dim myCell As Range

Dim res As Variant 'could be an error

Dim HowManyColsToCopy As Long

HowManyColsToCopy = 23

Set PTRWks = Worksheets("PTR")
Set RefWks = Worksheets("Reference data")

With PTRWks
'row 1 of PTR has headers???
Set PTRRng = .Range("a2", .Cells(.Rows.Count, "A").End(xlUp))
'remove any existing values in X to ???
.Range("x1").EntireColumn.Resize(, HowManyColsToCopy).ClearContents
End With

With RefWks
Set RefRng = .Range("A:A") 'use the whole column to match
End With

For Each myCell In PTRRng.Cells
If myCell.Value = "" Then
'skip it
Else
res = Application.Match(myCell.Value, RefRng, 0)
If IsError(res) Then
'no match, skip it
Else
'copies the key, too
RefRng(res).Resize(1, HowManyColsToCopy).Copy _
Destination:=PTRWks.Cells(myCell.Row, "X")
End If
End If
Next myCell

End Sub

Kcope8302 wrote:

The macro that I am looking for compares column A between 2 different
worksheets(PTR and Reference data). If the Macro finds a match it takes that
row from Reference data worksheet and copies it to the PTR worksheet starting
at column X. There is information from a macro ran before this that
populates PTR. After the initial information I want the information from the
Reference data worksheet to be placed into the PTR worksheet for reporting
purposes.

Example:
Row 6 in PTR and Row 3 in Reference data match(both contain €˜CR239492€„¢).
Once the match is found the macro takes all of row 3 from Reference data and
pastes it to Row 6 of PTR starting at column X.
Please do provide me as much assistance as possible

Thanks

-Keith-


--

Dave Peterson



  #6   Report Post  
Posted to microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 44
Default Copy entire row to different worksheet

Hello Bernie,

I keep getting #NA in the X column. Would you be able to assist. TO further
elaborate it is just supposed to compare column A and if they match copy
L,M,N,O to the PTR worksheet.

So looking at what you provided can I copy it and have it still compare
column A between PTR and Reference Data and have it copy the relevant data.

Example: There is a match between CR94875 and it paste the relevant data
from Reference Data into PTR.

PTR .......... X Y Z AA

CR94875 TBD On-Time 5/25/09 Source List
CR94483
CR02948


Reference Data L M N O
CR94875 TBD On-Time 5/25/09 Source List


"Bernie Deitrick" wrote:

Keith,

In Cell X6, use a formula like this in X6 of PTR:

=IF(ISERROR(VLOOKUP($A6,'Reference Data'!$A$1:$Z$10000,COLUMN(B1),FALSE)),"",VLOOKUP( $A6,'Reference
Data'!$A$1:$Z$10000,COLUMN(B1),FALSE))

Then copy to the right and down for as many rows and columns as you need. Change the range address
'Reference Data'!$A$1:$Z$10000 to match your data table on reference data...


HTH,
Bernie
MS Excel MVP


"Kcope8302" wrote in message
...
The macro that I am looking for compares column A between 2 different
worksheets(PTR and Reference data). If the Macro finds a match it takes that
row from Reference data worksheet and copies it to the PTR worksheet starting
at column X. There is information from a macro ran before this that
populates PTR. After the initial information I want the information from the
Reference data worksheet to be placed into the PTR worksheet for reporting
purposes.

Example:
Row 6 in PTR and Row 3 in Reference data match(both contain 'CR239492').
Once the match is found the macro takes all of row 3 from Reference data and
pastes it to Row 6 of PTR starting at column X.
Please do provide me as much assistance as possible

Thanks

-Keith-




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
If statement to copy an entire row to other worksheet w/ in same b hshayh0rn Excel Worksheet Functions 7 May 1st 09 09:05 PM
how do I copy an entire worksheet to another with text & format? kb Excel Discussion (Misc queries) 15 July 4th 08 09:25 PM
Copy Entire Sheet Linda Excel Discussion (Misc queries) 1 June 11th 06 11:04 PM
Is there a function to copy an entire worksheet? nickclingan Excel Worksheet Functions 3 December 23rd 05 03:23 PM
need a formula to copy entire row to next worksheet aledger Excel Worksheet Functions 5 March 8th 05 12:45 AM


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