Sub Upload()
Dim WS1 As Worksheet
Dim WS2 As Worksheet
Dim rng As Range
Dim rng2 As Range
Dim shname As Variant
With Application
.ScreenUpdating = True
.EnableEvents = True
End With
'Name of the worksheet with the data and the destination sheet
Set WS1 = Sheets("TH") '<<< Change
Set WS2 = Sheets("Upload") '<<< Change
WS2.Activate
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).ClearContents
Range("A1").Select
'Set filter range : A1 is the top left cell of your filter range and
'the header of the first column, D is the last column in the filter range
Set rng = WS1.Range("A6:E" & Rows.Count)
'Firstly, remove the AutoFilter
WS1.AutoFilterMode = False
'This example filters on the first column in the range (change the field if needed)
'In this case the range starts in A so Field:=1 is column A, 2 = column B, ......
'Use "<>Netherlands" if you want the opposite
rng.AutoFilter Field:=1, Criteria1:="<>*-*", Operator:=xlAnd, Criteria2:="*.*"
'Copy the visible data and use PasteSpecial to paste to the new worksheet
With WS1.AutoFilter.Range
On Error Resume Next
' Set rng2 to rng without the header row
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng2 Is Nothing Then
'Copy and paste the cells into WS2 below the existing data
rng2.Copy
With WS2.Range("A" & lastrow(WS2) + 1)
' Paste:=8 will copy the columnwidth in Excel 2000 and higher
'.PasteSpecial Paste:=8
.PasteSpecial xlPasteValues
'.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With
'Delete the rows in WS1
'rng2.EntireRow.Delete
End If
End With
With WS2
.Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).FormulaR1C1 = "TH Undistributed Stores Exp"
.Range(.Cells(.Rows.Count, "B").End(xlUp), .Cells(.Rows.Count, "A").End(xlUp).Offset(, 1)).FillDown
End With
WS1.AutoFilterMode = False
'Name of the worksheet with the data and the destination sheet
Set WS1 = Sheets("NM") '<<< Change
Set WS2 = Sheets("Upload") '<<< Change
'Set filter range : A1 is the top left cell of your filter range and
'the header of the first column, D is the last column in the filter range
Set rng = WS1.Range("A6:E" & Rows.Count)
'Firstly, remove the AutoFilter
WS1.AutoFilterMode = False
'This example filters on the first column in the range (change the field if needed)
'In this case the range starts in A so Field:=1 is column A, 2 = column B, ......
'Use "<>Netherlands" if you want the opposite
rng.AutoFilter Field:=1, Criteria1:="<>*-*", Operator:=xlAnd, Criteria2:="*.*"
'Copy the visible data and use PasteSpecial to paste to the new worksheet
With WS1.AutoFilter.Range
On Error Resume Next
' Set rng2 to rng without the header row
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng2 Is Nothing Then
'Copy and paste the cells into WS2 below the existing data
rng2.Copy
With WS2.Range("A" & lastrow(WS2) + 1)
' Paste:=8 will copy the columnwidth in Excel 2000 and higher
'.PasteSpecial Paste:=8
.PasteSpecial xlPasteValues
'.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With
'Delete the rows in WS1
'rng2.EntireRow.Delete
End If
End With
With WS2
.Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).FormulaR1C1 = "NM Undistributed Stores Exp"
.Range(.Cells(.Rows.Count, "B").End(xlUp), .Cells(.Rows.Count, "A").End(xlUp).Offset(, 1)).FillDown
End With
WS1.AutoFilterMode = False
'Name of the worksheet with the data and the destination sheet
Set WS1 = Sheets("Holden") '<<< Change
Set WS2 = Sheets("Upload") '<<< Change
'Set filter range : A1 is the top left cell of your filter range and
'the header of the first column, D is the last column in the filter range
Set rng = WS1.Range("A6:E" & Rows.Count)
'Firstly, remove the AutoFilter
WS1.AutoFilterMode = False
'This example filters on the first column in the range (change the field if needed)
'In this case the range starts in A so Field:=1 is column A, 2 = column B, ......
'Use "<>Netherlands" if you want the opposite
rng.AutoFilter Field:=1, Criteria1:="<>*-*", Operator:=xlAnd, Criteria2:="*.*"
'Copy the visible data and use PasteSpecial to paste to the new worksheet
With WS1.AutoFilter.Range
On Error Resume Next
' Set rng2 to rng without the header row
Set rng2 = .Offset(1, 0).Resize(.Rows.Count - 1, .Columns.Count) _
.SpecialCells(xlCellTypeVisible)
On Error GoTo 0
If Not rng2 Is Nothing Then
'Copy and paste the cells into WS2 below the existing data
rng2.Copy
With WS2.Range("A" & lastrow(WS2) + 1)
' Paste:=8 will copy the columnwidth in Excel 2000 and higher
'.PasteSpecial Paste:=8
.PasteSpecial xlPasteValues
'.PasteSpecial xlPasteFormats
Application.CutCopyMode = False
End With
'Delete the rows in WS1
'rng2.EntireRow.Delete
End If
End With
With WS2
.Columns("C:D").Delete Shift:=xlToLeft
.Range("C1").FormulaR1C1 = "Value"
.Range("D1").FormulaR1C1 = "Ref1"
.Range("E1").FormulaR1C1 = "Ref2"
.Range("F1").FormulaR1C1 = "Ref3"
.Range("G1").FormulaR1C1 = "Ref4"
.Range("H1").FormulaR1C1 = "Ref5"
.Range("I1").FormulaR1C1 = "Ref6"
.Range("J1").FormulaR1C1 = "DebCred"
.Range("K1").FormulaR1C1 = "DueDate"
.Cells(Rows.Count, "B").End(xlUp).Offset(1, 0).FormulaR1C1 = "Holden Undistributed Stores Exp"
.Range(.Cells(.Rows.Count, "B").End(xlUp), .Cells(.Rows.Count, "A").End(xlUp).Offset(, 1)).FillDown
.Columns("C:C").Style = "Comma"
End With
WS1.AutoFilterMode = False
WS2.Activate
Rows("2:2").Select
Range(Selection, Selection.End(xlDown)).Sort Key1:=Range("A2"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortTextAsNumbers
Range("A1").Select
End Sub
Function lastrow(sh As Worksheet)
On Error Resume Next
lastrow = sh.Cells.Find(What:="*", _
After:=sh.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlValues, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
Bookmarks