Also dann mal der Reihe nach:
03.03.2014 16:05:18
EtoPHG
Josef,
1. Lösche alle deine Makro-Codes. Es macht keinen Sinn in ListObjects (Tabellen) Formeln auf Vorrat zu füllen. Diese Formeln werden automatisch ergänzt, wenn neue Datensätze in die Tabelle eingefüllt werden.
2. Lösche in der Tabelle "FA" ab Zeile 136 alle Zeilen bis zum Ende!
3. Formatiere Spalte C in der Tabelle "Bestellübersicht" als Standard (das sind doch Zahlen und nicht Texte!)
4. Füge nur diesen Code für den Button ein. Er sollte genau das machen, was du beschrieben hast:
Private Sub CommandButton1_Click()
Dim wsQ As Worksheet
Dim lNextRow As Long
Dim lLastRow As Long
Set wsQ = ThisWorkbook.Worksheets("Bestellübersicht")
lNextRow = Cells(Rows.Count, 4).End(xlUp).Offset(1, 0).Row ' Nächste freie Zeile aufgrund _
Spalte D
lLastRow = wsQ.Cells(wsQ.Rows.Count, 1).End(xlUp).Row ' Letzte besetzte Zeile in _
Quelle Spalte A
wsQ.Range(wsQ.Cells(2, 2), wsQ.Cells(lLastRow, 2)).Copy _
Destination:=Cells(lNextRow, 4) ' Spalte B -> D
wsQ.Range(wsQ.Cells(2, 3), wsQ.Cells(lLastRow, 3)).Copy _
Destination:=Cells(lNextRow, 5) ' Spalte C -> E
wsQ.Range(wsQ.Cells(2, 5), wsQ.Cells(lLastRow, 5)).Copy _
Destination:=Cells(lNextRow, 3) ' Spalte E -> C
Range(Cells(lNextRow, 3), Cells(lNextRow + lLastRow - 1, 3)).Replace _
What:="00.01.1900", Replacement:="31.12.2015", LookAt:= _
xlWhole, SearchOrder:=xlByRows, MatchCase:=False, SearchFormat:=False
With ActiveSheet.ListObjects("Tabelle_Abfrage_von_NAVISION_DECK_1")
.Sort.SortFields.Clear
.Sort.SortFields.Add Key:=Range( _
.Name & "[Item No_]"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
.Sort.SortFields.Add Key:=Range( _
.Name & "[Due Date]"), SortOn:=xlSortOnValues, _
Order:=xlAscending, DataOption:=xlSortNormal
With .Sort
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End With
End Sub
Gruess Hansueli