Automatically Sorting of Excel Records
Hello Mr IT
This should do what you want, in terms of splitting the data into two
sheets. The sort assumes you start putting data in Range A1 and the
data is presented in a structured manner.
Take care
Marcus
Sub CopytoSheet()
Dim RngCell As Range
Dim MyList() As Variant
Dim res As Variant
Dim lw As Long
Dim X As Range
Dim ws As Worksheet
lw = Range("B" & Rows.Count).End(xlUp).Row
MyList() = Array("W", "X")
Set X = Range("B2:B" & lw)
For Each RngCell In X
res = Application.Match(RngCell.Value, MyList, 0)
If IsError(res) Then
RngCell.EntireRow.Copy Sheets("Sheet3"). _
Range("A65536").End(xlUp).Offset(1, 0)
Else
RngCell.EntireRow.Copy Sheets("Sheet2"). _
Range("A65536").End(xlUp).Offset(1, 0)
End If
Next RngCell
'Sort the ranges
For Each ws In ThisWorkbook.Worksheets
If ws.Name = "Sheet2" Or ws.Name = "Sheet3" Then
With ws.Range("A1").CurrentRegion
.Sort Key1:=.Cells(2, "A"), Order1:=xlDescending,
Header:=xlYes
End With
End If
Next
End Sub
|