views:

17

answers:

2

I have two excel files which has similar formatting and the data map each other from cell b15:h31. Row 15 is heading and so is the column B. I want to read file1 cell by cell and add that cell's content to the corresponding cell in File 2 i.e C16 in file 1 gets added to C16 in file 2, C17 in file 1 to C17 in file 2 and so on. The output goes in file 3 or anything. trying to implement through vba but of no success so far. Does anyone know how to go about it.

+1  A: 

I don't know that exact coding but I would :

open both files to read from
open 3rd file to write to
read in the first line from the first and second file
split these two lines with the separator used into an array of values
      (for instance I seperate cells with a comma when writing to an excel file)
go through these array (this would equate to going through a row in both files)
  foreach value in the array add the value from the first with the value from the second
  print it to the 3rd file and the print the cell separator (comma)
go on to the next value until you reach the end of the 'row'
print a newline character into the 3rd file to go to the next row
then read the next line of the first and second file, repeat til done reading files
close the input and output files
Kyra
+1  A: 

Kyra has the logic nailed down for you. If you're looking for syntax, use

Application.Workbooks.Open ("file2.xls")
Application.Workbooks.Open ("file3.xls")

to open,

Workbooks("file3.xls").Activate

to activate the workbook to read from or write to, and then

Workbooks("file3.xls").Activate
Workbooks("file3.xls").Save
Workbooks("file3.xls").Close

to save and close.

BenV