uit een ander bestand probeer ik data over te halen. het openen van het bron bestand gaat goed, het daarna uitlezen en overhalen werkt niet. wat doe ik fout?
Sub verticaal_zoeken()
'
' verticaal_zoeken Macro
'
Dim oBoek1 As Object
Dim oBoek2 As Object
Dim sh1a As Object
Dim sh1b As Object
Dim fDialoog As FileDialog
Dim sBestandsnaam As String
Dim sNaam As String
Dim sPad As String
Dim objBs As Variant
'Stel het werkboek en het pad in.
Set oBoek1 = ThisWorkbook
sPad = oBoek1.Path
'Pas het filedialoog aan en open het
Set fDialoog = Application.FileDialog(msoFileDialogOpen)
With fDialoog
.Title = "Selecteer het in te lezen Werboek"
.ButtonName = "Kopieer bord"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "excel", "*.xls*"
.InitialView = msoFileDialogViewDetails
.InitialFileName = sPad
.Show
'Haal bestandsnaam op.
For Each objBs In .SelectedItems
sBestandsnaam = objBs
Next objBs
End With
'open het werkboek
Workbooks.Open sBestandsnaam
'klaarmaken voor kopiëeren
With Application
.EnableEvents = False
.ScreenUpdating = False
.DisplayAlerts = False
End With
'kopieer en plak; oboek2 is het in te lezen bestand (bronbestand)
Set oBoek1 = ActiveWorkbook
Set sh1a = oBoek1.Worksheets("voorcalculatie")
Set sh1b = oBoek2.Worksheets("std")
On Error Resume Next
Dim Dept_Row As Long
Dim Dept_Clm As Long
table1 = sh1a.Range("B10:B20")
'*kolom tabel 1 die aangevuld wordt waarin kolom B de overeenkomende data staat van tabel 2
table2 = sh1b.Range("C10:FO200")
'referende tabelkolom van tabel 2 waarop vergeleken wordt en waaruit data naar tabel 1 wordt gebracht
Dept_Row = sh1a.Range("C10").Row
'startrij van bewerken**
Dept_Clm* = sh1a.Range("C10").Column
'startkolom van bewerken**
For Each cl In table1
sh1a.Cells(Dept_Row, Dept_Clm) = Application.WorksheetFunction.VLookup(cl, table2, sh1a.Range("C9"), False)
'sh1a.Cells(Dept_Row, Dept_Clm) = Application.WorksheetFunction.VLookup(cl, table2, 2, False)
Dept_Row = Dept_Row + 1
Next cl
MsgBox "Done"
Application.ScreenUpdating = True
End Sub
Sub verticaal_zoeken()
'
' verticaal_zoeken Macro
'
Dim oBoek1 As Object
Dim oBoek2 As Object
Dim sh1a As Object
Dim sh1b As Object
Dim fDialoog As FileDialog
Dim sBestandsnaam As String
Dim sNaam As String
Dim sPad As String
Dim objBs As Variant
'Stel het werkboek en het pad in.
Set oBoek1 = ThisWorkbook
sPad = oBoek1.Path
'Pas het filedialoog aan en open het
Set fDialoog = Application.FileDialog(msoFileDialogOpen)
With fDialoog
.Title = "Selecteer het in te lezen Werboek"
.ButtonName = "Kopieer bord"
.AllowMultiSelect = False
.Filters.Clear
.Filters.Add "excel", "*.xls*"
.InitialView = msoFileDialogViewDetails
.InitialFileName = sPad
.Show
'Haal bestandsnaam op.
For Each objBs In .SelectedItems
sBestandsnaam = objBs
Next objBs
End With
'open het werkboek
Workbooks.Open sBestandsnaam
'klaarmaken voor kopiëeren
With Application
.EnableEvents = False
.ScreenUpdating = False
.DisplayAlerts = False
End With
'kopieer en plak; oboek2 is het in te lezen bestand (bronbestand)
Set oBoek1 = ActiveWorkbook
Set sh1a = oBoek1.Worksheets("voorcalculatie")
Set sh1b = oBoek2.Worksheets("std")
On Error Resume Next
Dim Dept_Row As Long
Dim Dept_Clm As Long
table1 = sh1a.Range("B10:B20")
'*kolom tabel 1 die aangevuld wordt waarin kolom B de overeenkomende data staat van tabel 2
table2 = sh1b.Range("C10:FO200")
'referende tabelkolom van tabel 2 waarop vergeleken wordt en waaruit data naar tabel 1 wordt gebracht
Dept_Row = sh1a.Range("C10").Row
'startrij van bewerken**
Dept_Clm* = sh1a.Range("C10").Column
'startkolom van bewerken**
For Each cl In table1
sh1a.Cells(Dept_Row, Dept_Clm) = Application.WorksheetFunction.VLookup(cl, table2, sh1a.Range("C9"), False)
'sh1a.Cells(Dept_Row, Dept_Clm) = Application.WorksheetFunction.VLookup(cl, table2, 2, False)
Dept_Row = Dept_Row + 1
Next cl
MsgBox "Done"
Application.ScreenUpdating = True
End Sub