2016-06-22 3 views
0

Ich kopiere Daten von einem Blatt mit gestrigen Informationen auf ein anderes Blatt mit einer Tabelle mit historischen Daten. Das erste Blatt ist eigentlich eine vlookup Formel, also muss ich den Wert nur in die historische Tabelle einfügen. Dies ist, was ich geschrieben habe, aber es sagt, dass die letzte Zeile nicht funktioniert. Kann jemand helfen?Kopieren und Einfügen von Werten an ein Ziel

Option Explicit 


Sub Test() 
' 
' UpdateTablesAndCharts Macro 
' 
' Keyboard Shortcut: Option+Cmd+t 
' 


Dim lngNextEmptyRow As Long 
Dim lngLastImportRow As Long 
Dim shtYstrdy As Worksheet 
Set shtYstrdy = ThisWorkbook.Worksheets("Yesterday") 

With ThisWorkbook.Worksheets("ICT Historical Crashlytics Data") 
lngNextEmptyRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1 
.Rows(lngNextEmptyRow).Insert Shift:=xlDown 
.Cells(lngNextEmptyRow, "A").Value2 = _ 
    .Cells(lngNextEmptyRow - 1, "A").Value2 + 1 
shtYstrdy.Range("AM1:AN1").Copy 
    Cells("A" & lngNextEmptyRow).PasteSpecial xlPasteValues 


End With 

End Sub 

Antwort

3
  1. Zellen() Format ist Cells(Rows,Column) Sie wahrscheinlich Bereich möchten().

  2. Wenn Sie die Werte einfach einfügen, ist es schneller, sie direkt zuzuweisen.

  3. Der Cells() fehlte die . vor, so dass es nicht dem richtigen Elternblatt zugeordnet wurde.

verwenden:

Sub Test() 
' 
' UpdateTablesAndCharts Macro 
' 
' Keyboard Shortcut: Option+Cmd+t 
' 


Dim lngNextEmptyRow As Long 
Dim lngLastImportRow As Long 
Dim shtYstrdy As Worksheet 
Set shtYstrdy = ThisWorkbook.Worksheets("Yesterday") 

With ThisWorkbook.Worksheets("ICT Historical Crashlytics Data") 
    lngNextEmptyRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1 
    .Rows(lngNextEmptyRow).Insert Shift:=xlDown 
    .Cells(lngNextEmptyRow, "A").Value2 = _ 
     .Cells(lngNextEmptyRow - 1, "A").Value2 + 1 
    .Range("A" & lngNextEmptyRow).Resize(1, 2).Value = shtYstrdy.Range("AM1:AN1").Value 
End With 

End Sub 
+0

Aus irgendeinem Grund es ist immer noch nicht, dass die letzte Zeile nehmen. Was macht Resize? –

+0

Was ist der Fehler? –

+0

wird nicht kompiliert, weil es einen Syntaxfehler gibt –