Необходимо открыть два файла Excel и добавить номера из них в третий файл с помощью VBA - PullRequest
0 голосов
/ 16 июня 2010

У меня есть два файла Excel, которые имеют одинаковое форматирование и сопоставляют данные друг с другом из ячейки b15: h31. Строка 15 является заголовком, как и столбец B. Я хочу прочитать file1 ячейка за ячейкой и добавить содержимое этой ячейки в соответствующую ячейку в файле 2, т.е. C16 в файле 1 добавляется к C16 в файле 2, C17 в файле 1 - C17. в файле 2 и так далее. Вывод идет в файл 3 или что-нибудь. пытаюсь реализовать через vba, но пока безуспешно. Кто-нибудь знает, как это сделать.

Ответы [ 2 ]

1 голос
/ 16 июня 2010

У Киры есть логика для вас. Если вы ищете синтаксис, используйте

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

открыть,

Workbooks("file3.xls").Activate

для активации книги для чтения или записи, а затем

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

для сохранения и закрытия.

1 голос
/ 16 июня 2010

Я не знаю точного кодирования, но я бы:

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
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...