View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
STEVE BELL STEVE BELL is offline
external usenet poster
 
Posts: 692
Default Compare/Copy columns from two books?

Something like the following might work [untested]
The tricky part is assigning the workbook names.
(set "A" to the column you are working with, same with B & C)

Dim wkbk1 as workbook, wkbk2 as workbook, wkbk3 as workbook, x as long, lrw
as long

set wkbk1 = Workbooks("Workbook1")
set wkbk2 = Workbooks("Workbook2")
set wkbk3 = Workbooks("Workbook3")

For x = 1 to 30
lrw = wkbk1.Sheets(x).Cells(Rows.COUNT, "A").End(xlUp).Row
wkbk1.Sheets(x).Range("A1:A" & lrw).Copy _
Destination:=wkbk3.Sheets(x).Range("A1")

lrw = wkbk2.Sheets(x).Cells(Rows.COUNT, "A").End(xlUp).Row
wkbk2.Sheets(x).Range("A1:A" & lrw).Copy _
Destination:=wkbk3.Sheets(x).Range("B1")

wkbk3.Sheets(x).Range("C1:C" & lrw).FormulaR1c1="=RC[-2]-RC[-1]"
Next
--
steveB

Remove "AYN" from email to respond
"dailo" wrote in message
...

I've been searching throughout this forum and have found lots of
examples but none of them seem to do quite what I want.

I have two wookbooks which are formatted identical and I want to copy a
column from each workbook (numeral values) and then in a third column
display the difference between the values. Each workbook has 30 sheets
and I would like it to go through all 30 sheets copying a particular
column from each one and then comparing them and display the difference
into a new workbook that contains 30 sheets with each sheet containing
the values from both books and the difference. Thanks for your help!


--
dailo
------------------------------------------------------------------------
dailo's Profile:
http://www.excelforum.com/member.php...o&userid=25500
View this thread: http://www.excelforum.com/showthread...hreadid=389444