❶ 一个文件夹中有若干EXCEL,合并多个excel文件,同时文件名称改为列名称,求vba代码,
很简单,但是要求要具体一点:1、合并后的表:第1列是取某张表的第1列,还是所有表的第1列的并集?2、文件夹中的Excel,都是.xls格式的文件吗? 3、合并后的Excel文件保存在哪?
❷ 怎样用vba合并同一目录下所有excel文件
试试下面的代码:
SubMacro1()DimMyPath$,MyName$,shAsWorksheet,m&,wAsWorksheetFunction,wbAsWorkbookApplication.ScreenUpdating=FalseApplication.DisplayAlerts=FalseSetw=WorksheetFunctionMyPath=ThisWorkbook.Path&"采集多数据"MyName=Dir(MyPath&"*.xls*")[a1].CurrentRegion.Offset(1).ClearContentsDoWhileMyName<>""WithGetObject(MyPath&MyName)With.Sheets(1)Ifw.CountA(.UsedRange.Offset(1))Thenm=m+1Ifm=1ThenSetwb=Workbooks.Add(xlWBATWorksheet)Setsh=wb.ActiveSheet.[a1].CurrentRegion.Copysh.[a1]Else.[a1].CurrentRegion.Offset(1).Copysh.[a65536].End(xlUp).Offset(1)EndIfEndIfEndWith.CloseFalseEndWithMyName=DirLoopwb.SaveAsFilename:=ThisWorkbook.Path&"采集多数据20130422.xls",FileFormat:=xlExcel8wb.CloseApplication.ScreenUpdating=TrueMsgBox"ok"EndSub
❸ 怎么把excel文件合并到一起
把Excel文件合并到一起可以使用以下方法:1、直接打开Excel文件进行移动复制表格进行合并;2、利用VBA编程进行合并;3、利用WPS表格的合并功能:依次单击“数据”选项卡-“合并表格”-“合并工作簿”-“添加Excel文件”-“开始合并”。
❹ vba怎么合并不同的excel文件
合并的代码如下:Sub 合并表格() Dim mypath As String Dim f As String Dim ribao As Workbook Application.ScreenUpdating = False mypath = ThisWorkbook.Path & "/xxx/" f = Dir(ThisWorkbook.Path & "xxx/*.xlsx") Do Workbooks.Open (mypath & f) With ActiveWorkbook .Sheets(1).Move after:=ThisWorkbook.Sheets(Sheets.Count) End With f = Dir Loop Until Len(f) = 0 Application.ScreenUpdating = TrueEnd Sub
❺ 求一个VBA,一个文件夹中多个EXCEL工作簿合并成一个工作表
1、将需要合并的EXCEL文件与目的EXCEL文件放在一个文件夹下。
❻ VBA合并多个结构相同的Excel文件
Sub 合并当前目录下所有工作簿的全部工作表() Dim MyPath, MyName, AWbName Dim Wb As Workbook, WbN As String Dim G As Long Dim Num As Long Dim BOX As String Application.ScreenUpdating = False MyPath = ActiveWorkbook.Path MyName = Dir(MyPath & "\" & "*.xls") AWbName = ActiveWorkbook.Name Num = 0 Do While MyName <> "" If MyName <> AWbName Then Set Wb = Workbooks.Open(MyPath & "\" & MyName) Num = Num + 1 With Workbooks(1).ActiveSheet .Cells(.Range("A65536").End(xlUp).Row + 2, 1) = Left(MyName, Len(MyName) – 4) For G = 1 To Sheets.Count Wb.Sheets(G).UsedRange.Copy .Cells(.Range("A65536").End(xlUp).Row + 1, 1) Next WbN = WbN & Chr(13) & Wb.Name Wb.Close False End With End If MyName = Dir Loop Range("A1").Select Application.ScreenUpdating = True MsgBox "共合并了" & Num & "个工作薄下的全部工作表。如下:" & Chr(13) & WbN, vbInformation, "提示" End Sub
❼ 用Excel VBA如何合并同一文件夹下的所有工作簿的第一张工作表
您好!
答案如下,请参考。
比如,下图为公司各部门员工的KPI信息,我们要把它们汇总到同一工作簿中。
此方案主要功能:
⓵单击“合并所有工作簿”命令按钮,系统自动实现合并功能;
⓶执行命令后,系统自动弹出一“提示”对话框,显示合并的工作簿信息;
⓷当部门员工的信息有更改时,再次单击按钮,汇总数据随时刷新。
实现以上功能的代码如下:
Sub CombineWbs()
Dim bt As Range, r As Long, c As Long
r = 1
c = 7
Dim wt As Worksheet
Set wt = ThisWorkbook.Worksheets(1)
wt.Rows(r + 1 & ":1048576").ClearContents
Application.ScreenUpdating = False
Dim FileName As String, sht As Worksheet, wb As Workbook, WbN As String
Dim Erow As Long, fn As String, arr As Variant, Num As Long
FileName = Dir(ThisWorkbook.Path & "*.xlsx")
Num = 0
Do While FileName <> ""
If FileName <> ThisWorkbook.Name Then
Erow = wt.Range("A1").CurrentRegion.Rows.Count + 1
fn = ThisWorkbook.Path & "" & FileName
Set wb = GetObject(fn)
Set sht = wb.Worksheets(1)
Num = Num + 1
arr = sht.Range(sht.Cells(r + 1, "A"), sht.Cells(1048576, "B").End(xlUp).Offset(0, 7))
wt.Cells(Erow, "A").Resize(UBound(arr, 1), UBound(arr, 2)) = arr
WbN = WbN & Chr(13) & wb.Name
wb.Close False
End If
FileName = Dir
Loop
Application.ScreenUpdating = True
MsgBox "共合并了" & Num & "个工作薄下的全部工作表。如下:" & Chr(13) & WbN, vbInformation, "提示"
End Sub
希望以上的方法可以帮助到你。谢谢!
❽ excel vba公式合并
Subs()n=Cells(Rows.Count,3).End(3).Row[y2]=(10+Cells(n-1,3)+Cells(n,4)-Cells(n,8))Mod10&(10+Cells(n-1,4)+Cells(n,5)-Cells(n,9))Mod10EndSub
❾ 用excel的VBA合并汇总多个工作薄,每个工作薄的格式一样,需要合并的内
1原始数据所在工作簿包含多个格式相同的工作表,只不过每个工作表内容不同,比如说不同人名的工作表数据或者不同部门填写的数据。2在原始数据同目录下新建一个工作簿,建立两个工作表,名称分别为“首页”和“合并汇总表”。3按Alt+F11进入VBA代码编辑和调试界面。4根据提示,插入一个模块。5将下述代码粘贴到模块空白处:Sub CombineSheetsCells()Dim wsNewWorksheet As WorksheetDim cel As RangeDim DataSource, RowTitle, ColumnTitle, SourceDataRows, SourceDataColumns As VariantDim TitleRow, TitleColumn As RangeDim Num As IntegerDim DataRows As LongDataRows = 1Dim TitleArr()Dim ChoiceDim MyName$, MyFileName$, ActiveSheetName$, AddressAll$, AddressRow$, AddressColumn$, FileDir$, DataSheet$, myDelimiter$Dim n, in = 1i = 1Application.DisplayAlerts = FalseWorksheets("合并汇总表").DeleteSet wsNewWorksheet = Worksheets.Add(, after:=Worksheets(Worksheets.Count))wsNewWorksheet.Name = "合并汇总表"MyFileName = Application.GetOpenFilename("Excel工作薄 (*.xls*),*.xls*")If MyFileName = "False" ThenMsgBox "没有选择文件!请重新选择一个被合并文件!", vbInformation, "取消"ElseWorkbooks.Open Filename:=MyFileNameNum = ActiveWorkbook.Sheets.CountMyName = ActiveWorkbook.NameSet DataSource = Application.InputBox(prompt:="请选择要合并的数据区域:", Type:=8)AddressAll = DataSource.AddressActiveWorkbook.ActiveSheet.Range(AddressAll).SelectSourceDataRows = Selection.Rows.CountSourceDataColumns = Selection.Columns.CountApplication.ScreenUpdating = FalseApplication.EnableEvents = FalseFor i = 1 To NumActiveWorkbook.Sheets(i).ActivateActiveWorkbook.Sheets(i).Range(AddressAll).SelectSelection.CopyActiveSheetName = ActiveWorkbook.ActiveSheet.NameWorkbooks(ThisWorkbook.Name).ActivateActiveWorkbook.Sheets("合并汇总表").SelectActiveWorkbook.Sheets("合并汇总表").Range("A" & DataRows).Value = ActiveSheetNameActiveWorkbook.Sheets("合并汇总表").Range(Cells(DataRows, 2), Cells(DataRows, 2)).SelectSelection.PasteSpecial Paste:=xlPasteColumnWidths, Operation:=xlNone, _SkipBlanks:=False, Transpose:=FalseSelection.PasteSpecial Paste:=xlPasteAll, Operation:=xlNone, SkipBlanks:= _False, Transpose:=FalseSelection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _:=False, Transpose:=FalseDataRows = DataRows + SourceDataRowsWorkbooks(MyName).ActivateNext iApplication.ScreenUpdating = TrueApplication.EnableEvents = TrueEnd IfWorkbooks(MyName).CloseEnd Sub6在“首页”工作表中按下图示范插入一个窗体控件并指定宏为插入的代码名称。7点击“首页”工作表中插入的按钮,根据提示,浏览到原始数据工作簿。8下一步,用鼠标选择要合并的数据范围。注意:每个工作表数据可能不一样,比如说有的是10行数据,有的是30行数据。在这里我们可以用鼠标选择任意工作表的一个较大范围,比如说A1:D100,保证比最多行数的工作表数据还多就可以,一会再删除空行。9点击确定按钮,待代码运行完毕后,所有的数据就都合并到了“合并汇总表”中。注意:1)A列的文本说明右侧的数据来自于原始数据表的哪个工作表;2)数据之间会有一些空行,下面通过筛选删除。10选中全部数据区域,执行自动筛选。然后选择其中一个字段,选择“空白”和标题内容。11然后将筛选出来的无用行鼠标右键删除,再删除A列整列即可,完成效果
❿ 如何用vba合并多个excel文件到一个sheet里
新建一个工作薄,将所有EXCEL表的文件名填到A列中,复制下面VBA代码到工作薄中,保存为excel.xls后执行Subxls()Application.ScreenUpdating=False'Arr数组由所有EXCEL文件名组成arr=[A1:A10]Fori=1ToUBound(arr)Workbooks.Open"文件夹路径\"&arr(i,1)Workbooks(arr(i)(1)).ActivateForj=1ToActiveWorkbook.Sheets.CountSheets(j).CopyAfter:=Workbooks("excel.xls").Sheets(Workbooks("excel.xls").Sheets.Count)NextWorkbooks(arr(i,1)).CloseFalseNextEndSub
未经允许不得转载:山九号 » excelvba合并excel文件|怎样用vba合并同一目录下所有excel文件