Я хочу получить данные (регистрационные номера) столбца записи из листа Excel на другом листе Excel, когда имена столбцов совпадают.
То есть на листе «Созыв»есть
Matric Apellido Nombre Avión
12 Burrow Irving F15
42 Nelson Howard A10
18 Krings Jack F18
10 Mitaux-Maurouard Guy Rafale
И в листе "RECAP" у меня есть
Apellido Nombre ...
Nelson Howard ...
Burrow Irving ...
Mitaux-Maurouard Guy
Krings Jack ...
Y me gustaría
Apellido Nombre ... Matric
Nelson Howard ... 42
Burrow Irving ... 12
Krings Jack ... 18
Я пытался:
Sub Test()
Dim i As Long
Dim arr As Variant
Dim Matriculas As New Scripting.Dictionary 'Need the Microsoft Scripting Runtime library in Tools-> References
'We store the sheet with everything in an array
With ThisWorkbook.Sheets("Convocation")
arr = .UsedRange.Value
End With
'We assume that the registration is in column A and surnames B and C
For i = 2 To UBound(arr)
If arr(i, 1) = vbNullString Then Exit For 'if we find empty values we leave the loop
If Not Matriculas.Exists(arr(i, 2) & arr(i, 3)) Then 'we check that the combo of surnames is not duplicated
Matriculas.Add arr(i, 2) & arr(i, 3), arr(i, 1) 'we keep in the dictionary the combo of surnames with their registration
Else 'If the person could have more than 1 license plate then:
Matriculas(arr(i, 2) & arr(i, 3)) = Matriculas(arr(i, 2) & arr(i, 3)) & ", " & arr(i, 1) 'we add the others separated by ","
End If
Next i
'We store the sheet with everything in an array
With ThisWorkbook.Sheets("RECAP")
arr = .UsedRange.Value
'We assume that the surnames are in columns A and B, and the registration in C
For i = 2 To UBound(arr)
If arr(i, 1) = vbNullString Then Exit For 'if we find empty values we leave the loop
arr(i, 3) = Matriculas(arr(i, 1) & arr(i, 2)) 'here we assign the registration stored in the dictionary according to surnames
Next i
.UsedRange.Value = arr 'we return the array to the sheet
End With
End Sub
Но когда я компилирую, у меня появляется эта ошибка: Sub или Function не определены.Я поместил код в Microsoft Excel Objects
, который содержит все листы, в частности в ThisWorkbook
.
Редактировать: я знаю свою проблему
Моя проблема была не с первой строкой, нос Ubond
.Когда я избавляюсь от этого, у меня больше нет ошибок.Но они необходимы для петель.