Live-Forum - Die aktuellen Beiträge
Anzeige
Archiv - Navigation
1668to1672
Aktuelles Verzeichnis
Verzeichnis Index
Übersicht Verzeichnisse
Vorheriger Thread
Rückwärts Blättern
Nächster Thread
Vorwärts blättern
Anzeige
HERBERS
Excel-Forum (Archiv)
20+ Jahre Excel-Kompetenz: Von Anwendern, für Anwender
Inhaltsverzeichnis

Automatisierter Datenimport

Automatisierter Datenimport
21.01.2019 17:17:11
Henning
Hallo zusammen,
ich brauche mal eure Hilfe.
Ich würde gerne eine Excel-Maindatei, fortlaufend mit neuen Daten aus anderen Excel-Quelldateien füttern.
Jeden Tag entsteht eine neue Excel-Quelldatei, die mit dem aktuellen Datum abgespeichert wird. Die Quelldateien sehen alle gleich aus. Aus den Quelldateien benötige ich die Werte aus den Zellen B9, B10, B11 und B12.
Diese sollen in der Excel-Maindatei fortlaufend, beginnend beim 01.01.2019, runter geschrieben werden.
Datum Werte aus Quelldateien
01.01.2019 1 4 5 6
01.02.2019 3 1 5 8
vorab schon mal Vielen Dank.

2
Beiträge zum Forumthread
Beiträge zu diesem Forumthread

Betreff
Datum
Anwender
Anzeige
AW: Automatisierter Datenimport
21.01.2019 17:25:14
Sepp
Hallo Henning,
wie lauten die Dateinamen?
Auf welcher Tabelle stehen die Daten in den Quelldateien?
 ABCDEF
1Gruß Sepp
2
3

Anzeige
AW: Automatisierter Datenimport
21.01.2019 19:02:36
Sepp
Hallo Henning,
ich hab jetzt einfach mal angenommen, dass die dateien nach dem Schema 'JJJJMMTT.xls*' benannt sind.
Modul Modul1
Option Explicit 
 
Sub importData() 
  Dim strDate         As String 
  Dim strFile         As String 
  Dim strFormula      As String 
  Dim strPath         As String 
  Dim varRef          As Variant 
  Dim lngFirst        As Long 
  Dim lngIndex        As Long 
  Dim lngNext         As Long 
   
  Const conPATH_NAME  As String = "D:\Downloads\Forum" 'Pfad - Anpassen! 
  Const conTAB_NAME   As String = "Tabelle1" 'Tabellenname - Anpassen! 
   
  On Error GoTo ErrorHandler 
   
  With Application 
    .ScreenUpdating = False 
    .Calculation = xlManual 
  End With 
   
  varRef = Array("B9", "B10", "B11", "B12") 'Auszulesende Zellen. 
   
  With Tabelle1 
    strPath = conPATH_NAME & IIf(Right(conPATH_NAME, 1) = "\", "", "\") 
    lngNext = Application.Max(2, .Cells(.Rows.Count, 1).End(xlUp).Row + 1) 
    lngFirst = lngNext 
    strFile = Dir(strPath & "*.xls*", vbNormal) 
    Do While Len(strFile) 
      If strFile Like "########.*" Then 
        strDate = Mid(strFile, 7, 2) & "." & Mid(strFile, 5, 2) & "." & Left(strFile, 4) 
        If IsDate(strDate) Then 
          If IsError(Application.Match(CLng(CDate(strDate)), .Columns(1), 0)) Then 
            .Cells(lngNext, 1) = CDate(strDate) 
            strFormula = "='" & strPath & "[" & strFile & "]" & conTAB_NAME & "'!" 
            For lngIndex = 0 To Ubound(varRef) 
              .Cells(lngNext, lngIndex + 2).Formula = strFormula & varRef(lngIndex) 
            Next 
            lngNext = lngNext + 1 
          End If 
        End If 
      End If 
      strFile = Dir 
    Loop 
    If lngNext > lngFirst Then 
      With .Range(.Cells(lngFirst, 1), .Cells(lngNext, 5)) 
        .Calculate 
        .Value = .Value 
      End With 
    End If 
  End With 
   
ErrorHandler: 
   
  With Application 
    .ScreenUpdating = True 
    .Calculation = xlAutomatic 
  End With 
End Sub 

VBA/HTML-CodeConverter, AddIn für Office 2002-2016 - in VBA geschrieben von Lukas Mosimann. Projektbetreuung:RMH Software & Media

Code erstellt und getestet in Office 16 - mit VBAHTML 12.6.0


 ABCDEF
1Gruß Sepp
2
3

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige

Beliebteste Forumthreads (12 Monate)

Anzeige
Anzeige
Anzeige