Sub Foo
Dim Maestro As Workbook
Dim Libro_FormularioWB As Worksheet
Dim Origen_Datos As String
Dim i As String
Dim Carpeta As String
Dim Archivo As String
Dim Ruta As String
Dim Formato As String
Dim Errores As Integer
Dim Formulario As String
Dim Buscar_Cedula As Range
Dim Cedula As Integer
i = 5
Set Maestro = ThisWorkbook
Carpeta = ActiveWorkbook.Path
Formato = ".xlsm"
Origen = ThisWorkbook.Sheets("Data").Range("a" & i)
x = ThisWorkbook.Sheets("Data").Range("a" & i)
Formulario = Carpeta & "" & ThisWorkbook.Sheets("Data").Range("a" & i) & Formato
Set Buscar_Cedula = Maestro.Sheets("Resultados").Range("b1:zz1")
Do While ThisWorkbook.Sheets("Data").Range("a" & i) <> ""
If ThisWorkbook.Sheets("Data").Range("a" & i) > "" Then
ActiveWorkbook.FollowHyperlink Formulario
Windows(Origen & Formato).Activate
Range("B42:B53").Select
Application.CutCopyMode = False
Selection.Copy
Windows("ARCHIVO MAESTRO.xlsm").Activate
Maestro.Sheets("Resultados").Select
Application.WorksheetFunction.XLookup(x, Buscar_Cedula, Buscar_Cedula, , 0, 1).Offset(1, 0).Select
Selection.PasteSpecial Paste := xlPasteValues, Operation := xlNone,
SkipBlanks _ := False, Transpose := False
Windows(Origen & Formato).Close SAVECHANGES := False
On Error Resume Next
i = i + 1
Errores = Errores + 1
Loop
End Sub
我有下面的代码来搜索和opne一个文件从一个列表的值(id号码)复制一个特定范围的单元格,回到主工作簿和过去它.这个循环已经工作,但我定义了一个整数为i和它不更新,所以代码重复相同的范围.
origen应该随着整数的增长而变化,但它提醒了相同的事情。
1条答案
按热度按时间wj8zmpe11#
从关闭的工作簿导入数据
假设
Data
的5
行开始的A
列中有一个源库名称(不带扩展名的文件名)列表。Resultados
页的B1:ZZ1
中可以找到相同的名称。B42:B53
复制值,我选择了Sheet1
(调整它!),到工作表Resultados
的正确标题下。