LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 273
Default Macro to compare, find match and copy between workbooks

want to compare a user selection of cells (say A1:A10) in book2 to all
entries in book1 in column X. Find the matches and copy certain cells in the
matched row in book1 to book2.
this is what I have so far. It works except for the copy part.... it screws
up the selection for the loop.

Sub CompareAndCopy()

Dim xx As Long
Dim CompareRange As Variant, x As Variant, y As Variant

'first section to merge date and name togeter in book1.xls and copy to a
new (X) column. Book two has the name and date allready in column A


Windows("Book1.xls").Activate
'Have xx start at row 2
xx = 2
' Loop Through Target Depth & Objective until Blank Row is Found
Do While Cells(xx, 4).Value < ""
'This will put the values of the fourth and tenth column
'together with in column 24 with a space in between the orignal
cell contents
Cells(xx, 24).Value = Cells(xx, 4) & " " & Cells(xx, 10).Value
xx = xx + 1
Loop

'second section compares selected range in book2.xls to range X1:X1435
if there is a match I want to copy a range of cells from book1 to book2

Windows("Book2.xls").Activate
' Set CompareRange equal to the range to which you will
' compare the selection.

'Set CompareRange = Range("C1:C5")
' NOTE: If the compare range is located on another workbook
' or worksheet, use the following syntax.
Set CompareRange = Workbooks("Book1.xls"). _
Worksheets("Book1").Range("X1:X1435")
'
' Loop through each cell in the selection and compare it to
' each cell in CompareRange.

For Each x In Selection
For Each y In CompareRange
If x = y Then Windows("Book1.xls").Activate
Range("O2:V2").Select
Selection.copy
Windows("Book2.xls").Activate
Range("P12").Select
Selection.PasteSpecial Paste:=xlPasteValues,
Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Next y
Next x

End Sub
 
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
Compare Col A and Col M, if Match, Copy Col N to Col E ryguy7272 Excel Programming 5 March 21st 08 05:51 PM
Macro to compare two sheets and then copy if match [email protected] Excel Programming 0 November 29th 06 10:47 AM
Macro or VB to copy data between two workbooks by column A match Chuckak Excel Programming 0 September 2nd 06 02:39 PM
Is there a way to compare data on 2 different workbooks to find m. KcBran Excel Worksheet Functions 1 April 14th 05 10:28 PM
Find, Match, Compare or Search.... Help! Paulc Excel Programming 2 February 2nd 05 01:21 PM


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