我真的开始在VBA/编程只有基本的Python知识。
有6个不同的表在单独的文件,每天手动合并。它们都有相同的配置(A:D
本地号码,E:G
我需要编译的,H
等杂项信息,第一行作为标题)。
我想创建一个宏去每个文件,选择单元格E2:G(last row)
和粘贴它的文本在这个主文件没有空白行之间。
我已经搜索,尝试并调整了这里发现的多个代码,但它们都不能正常工作,所以我在这里寻求帮助。
我能够解决它,花了很多时间搜索通过VBA的方式…
这是最终的代码,100%工作:
Sub Teste_Array()
'Strings and paths definition
Dim Planilha() As Variant
Planilha = Array("03 - CONCRETO.xlsx", "04 - ALVENARIA.xlsx", "05 - METAIS.xlsx", "06 - MADEIRAS, PLÁSTICOS E COMPÓSITOS.xlsx", "07 - ABERTURAS.xlsx", "08 - ACABAMENTOS.xlsx")
Dim Caminho As String
Dim Abrir As String
Dim i As Integer
Dim LinhaFinal As Long
Caminho = "C:hd_servidor8 BIBLIOTECA3 REVITTEMPLATECATEGORIZAÇÃO"
'Cancel animations for faster process
Application.ScreenUpdating = False
Application.EnableEvents = False
'Clear Contents of current compilation
ThisWorkbook.Worksheets("TESTE").Activate
LinhaFinal = Cells(Rows.Count, 1).End(xlUp).Row
Range("A1:C" & LinhaFinal).ClearContents
'Loop, Copy and Paste to Compilation
For i = 0 To 5
Abrir = Caminho & Planilha(i)
Workbooks.Open (Abrir)
LinhaFinal = Cells(Rows.Count, 6).End(xlUp).Row
Range("E2:G" & LinhaFinal).Copy
ThisWorkbook.Worksheets("TESTE").Activate
LinhaFinal = Cells(Rows.Count, 1).End(xlUp).Row
Range("A" & LinhaFinal).PasteSpecial xlPasteValues
Application.CutCopyMode = False
Workbooks(Planilha(i)).Close
Next i
'Animations Back
Application.ScreenUpdating = True
Application.EnableEvents = True
End Sub
编辑后留下英文说明,因为我以前用葡萄牙语写过。