Rip1971
Board Regular
- Joined
- Nov 3, 2020
- Messages
- 65
- Office Version
- 365
- Platform
- Windows
Hi there,
i have a piece of code that somehow does not do what i would like. it does not give any errors maybe someone can point me in the right direction it would be appreciated.
i have a piece of code that somehow does not do what i would like. it does not give any errors maybe someone can point me in the right direction it would be appreciated.
VBA Code:
Sub CopyCat()
' deze wordt gebruikt voor het kopieren van category tov ordernr
Application.ScreenUpdating = False
Dim LastRow As Long, r As Long
Dim srcWS As Worksheet, desWS As Worksheet
Dim Ary As Variant, Nary As Variant
Dim Wbk As Workbook
Set desWS = ActiveWorkbook.Sheets("TA Inventory")
' het openen van de benodigde file voor invoeren data
On Error Resume Next
Set Wbk = Workbooks.Open("Source.xlsx")
On Error GoTo 0
If Wbk Is Nothing Then
Fname = Application.GetOpenFilename
If Fname = "False" Then Exit Sub
Set Wbk = Workbooks.Open(Fname)
End If
Set srcWS = Wbk.Sheets("Rip")
With srcWS
LastRow = .Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
Ary = .Range("A2:F" & LastRow).Value2
End With
With CreateObject("scripting.dictionary")
' Deze waarden aanpassen om de juiste kolom te controleren ".Item(Ary(r, 2)) = Ary(r, 1)"
' A=1, B=2, C=3, D=4, E=5, F=6
For r = 1 To UBound(Ary)
.Item(Ary(r, 1)) = Ary(r, 2)
Next r
LastRow = desWS.Cells.Find("*", SearchOrder:=xlByRows, SearchDirection:=xlPrevious).Row
' Lokatie invullen van kolom waarmee vergelijken moet worden
Ary = desWS.Range("A4:A" & LastRow).Value2
' Lokatie invullen van kolom waar data naar toe moet
Nary = desWS.Range("AO4:AO" & LastRow).Value2
For r = 1 To UBound(Ary)
If .Exists(Ary(r, 1)) Then Nary(r, 1) = .Item(Ary(r, 1))
Next r
End With
' lokatie invullen waar dat moet beginnen
desWS.Range("AO4").Resize(UBound(Nary)).Value = Nary
' sluiten van bron bestand
' Wbk.Close Savechanges:=False
Application.ScreenUpdating = True
End Sub