考虑2个Excel文档:Excel文件A和Excel文件B。这些Excel文件中有工作表(文件A有A、B、c工作表,文件B有d、e、f工作表)。
我需要复制文件A、工作表A(依此类推)中的内容,并将其粘贴到我的试错工作表的第二页。我知道我需要为此做循环,但仅此而已。
我对这个编程很陌生,更不用说VBA了。
我想把表a中的内容复制到我的第二张纸上,把表b中的内容拷贝到表3中,以此类推。
考虑2个Excel文档:Excel文件A和Excel文件B。这些Excel文件中有工作表(文件A有A、B、c工作表,文件B有d、e、f工作表)。
我需要复制文件A、工作表A(依此类推)中的内容,并将其粘贴到我的试错工作表的第二页。我知道我需要为此做循环,但仅此而已。
我对这个编程很陌生,更不用说VBA了。
我想把表a中的内容复制到我的第二张纸上,把表b中的内容拷贝到表3中,以此类推。
一些让你开始的提示
(我不完全清楚你想要的一些细节,但这应该会让你开始)
首先打开两个工作簿,在其中一个工作簿中创建一个模块(这与代码中的哪一个无关),然后运行宏
Option Explicit at top of module - forces explicit declaration of variables,
a good thing particularly while learning
Sub CopySheets()
Dim wbFileA As Workbook
Dim wbFileB As Workbook
Dim sh As Worksheet
Dim shCopAfter As Worksheet
Point to the workbooks
Set wbFileA = Application.Workbooks("NameOfFileA.xls")
Set wbFileB = Application.Workbooks("NameOfFileB.xls")
Set pointer to first sheet in FileB
Set shCopAfter = wbFileB.Sheets(1)
loop through the sheets in FileA
For Each sh In wbFileA.Sheets
Copy sheet to FileB
sh.Copy After:=shCopAfter
If last sheet in book then set shCopyAfter to last sheet
If ActiveSheet.Index >= wbFileB.Sheets.Count Then
Set shCopAfter = ActiveSheet
Else
Else set shCopyAfter to the one after the one just copied
Set shCopAfter = wbFileB.Sheets(ActiveSheet.Index + 1)
End If
Next
End Sub
Dim x as Integer
Dim wbA as Workbook, wbB as Workbook
Set wbA = Workbooks("FileA")
Set wbB = Workbooks("FileB")
For x=1 to wbA.Sheets.Count
wbA.sheets(x).Copy After:=wbB.sheets((2*x)-1)
Next x
Well, eight years after this question has been originally asked, Power Query has been integrated into Excel and comes to help. From your destination workbook (“B”) you can load the source worksheets from “A” following these steps.
此过程的好处是,在源数据更改的情况下,刷新目标“B”中的数据所需做的就是触发“数据”->;“全部刷新”。
For an Excel formula I need the first cell out of a list of cells which contains a numeric value: A | B | C | ... | Z | ----------------------------- | 0.1 | 0.4 | ... | =0.1 | | ...
I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...
The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...
I m using Application run to call several macros in order like this. Sub Run_All_Macros() Application.Run ("Macro_1") Application.Run ("Macro_1") End Sub When I start Run_All_Macros, all the ...
Does anyone know how to convert an Excel date to a correct Unix timestamp?
I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...
I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...
I have created an Add-In in C# that implements user defined functions for Excel. These UDF s return immediately, but they control background asynchronous procedures. These procedures have status ...