我有兩個excel文件,它們具有相似的格式和數據映射表b15:h31。行15是標題,列B也是。我想逐個讀取file1,並將該單元格的內容添加到文件2中的相應單元格,即將文件1中的C16添加到文件2中的C16,將文件1中的C17添加到C17在文件2中等等。輸出到文件3或任何東西。試圖通過vba實現,但迄今爲止沒有成功。有誰知道如何去做。需要打開兩個excel文件,並使用vba將數字添加到第三個文件中
0
A
回答
1
我不知道確切的編碼,但我想:
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
1
凱拉已經明確了你的邏輯。如果你正在尋找的語法,使用
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. 在VBA中打開並定義兩個excel文件
- 2. 打開兩個Excel文件
- 3. 如何將文件打開的密碼添加到由VBA excel文件
- 4. VBA打開Excel文件
- 5. VBA:打開一個xls文件並將其添加到當前工作簿
- 6. Activeadmin - 需要添加兩個值,並顯示在第三列
- 7. 使用兩個文件來查找/替換第三個文件
- 8. 使用兩個文件創建第三個文件
- 9. 的Python:比較兩個CSV文件,並打印出來,我需要比較兩個CSV文件,並打印出第三CSV文件的不同差異
- 10. VBA:如何在文件夾中打開最近的兩個excel文件
- 11. 打開文件夾中的每個文件並使用VBA刪除數據
- 12. 打開一個excel文件,並添加單元格的值
- 13. Excel - VBA問題。需要訪問的數據從所有目錄中的Excel文件,而無需打開文件
- 14. 從excel打開word文檔並將所需信息複製到excel文件中
- 15. MS EXCEL VBA - 我需要將工作表從一個excel文件導入到另一個excel文件
- 16. 使用Python打開多個excel文件
- 17. 比較unix中的兩個文件並將增量添加到一個文件
- 18. 在第三個文件中寫入兩個Excel文件的內容
- 19. shell腳本比較兩個文件並將差異寫入第三個文件
- 20. GIS:需要將數據添加到一個形狀文件
- 21. 批處理腳本合併兩個文件的行到第三個文件
- 22. 將兩個.IDL文件或兩個.tlb文件合併到一個文件中
- 23. 使用文件路徑Excel-VBA打開文件
- 24. 我需要從多個.txt文件中提取數據並將它們移動到Excel文件,使用Python
- 25. 如何將兩個文件(列)粘貼到第三個文件遞增行+1?
- 26. 如何將兩個excel文件合併到一個名稱中?
- 27. 將節點添加到第一個doctree並保存到文件
- 28. 使用Excel中的Excel VBA 2016打開PowerPoint文件
- 29. 根據第三個文件中的映射合併兩個文件
- 30. 需要比較兩個excel文件中的數據