Dim sti As String Dim fil1 As Workbook Dim antalRæk1 As Integer, ræk1 As Integer Dim id As Long
Const fil2Navn = "Ark2.xlsx" Dim fil2 As Workbook Dim ræk2 As Integer Public Sub opdaterData() houseKeeping
fil1.Sheets(1).Activate
For ræk1 = 2 To antalRæk1 id = ActiveSheet.Range("A" & ræk1)
ræk2 = findesIdArk2(id) If ræk2 > 0 Then hentDataFra2 ræk2, ræk1 Else ' Stop End If fil1.Activate Next ræk1
fil2.Close
ActiveSheet.Columns.AutoFit End Sub Private Sub houseKeeping() Application.ScreenUpdating = False
sti = ActiveWorkbook.Path Set fil1 = ActiveWorkbook antalRæk1 = ActiveSheet.Range("A65000").End(xlUp).Row
Workbooks.Open sti & "\" & fil2Navn Set fil2 = ActiveWorkbook End Sub Private Function findesIdArk2(kundeId) As Integer fil2.Activate With ActiveSheet.Range("A2:" & "A" & 65000) Set c = .Find(kundeId, LookIn:=xlValues, LookAt:=xlWhole) If Not c Is Nothing Then findesIdArk2 = c.Row Else findesIdArk2 = 0 End If End With End Function Private Sub hentDataFra2(ræk2, ræk1) fil2.ActiveSheet.Range("B" & ræk2 & ":D" & ræk2).Select Selection.Copy
fil1.Activate ActiveSheet.Range("H" & ræk1).Select ActiveSheet.Paste Application.CutCopyMode = False End Sub
Synes godt om
Ny brugerNybegynder
Din løsning...
Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.
Følg dette spørgsmålOpretPreview
Flere spørgsmål fra Office & Kontorpakker kategorien