R
Randy Reese
There are two sheets with combined data on them. i want to separate them and
put them on two diferent sheets column b is either the number 281 or 282. I
want them on "Print281" and "Print282".
They should be appending the print sheets. be they seem to be replacing
instead. Can anyone help??
----------------------------------------------------------------------------
--------------
Private Sub btnProcess_Click()
Dim WS As Worksheet
Dim WS2 As Worksheet
Dim Str As String
Dim LRow As Long
Set WS = Sheets("lod")
Set WS2 = Sheets("Print282")
LRow = LastRow(WS2)
Str = "282"
Call Copy_With_AutoFilter(WS, WS2, Str, LRow)
Set WS = Sheets("lod")
Set WS2 = Sheets("Print281")
LRow = LastRow(WS2)
Str = "281"
Call Copy_With_AutoFilter(WS, WS2, Str, LRow)
Set WS = Sheets("Unsc.")
Set WS2 = Sheets("Print281")
LRow = LastRow(WS2)
Str = "281"
Call Copy_With_AutoFilter(WS, WS2, Str, LRow)
Set WS = Sheets("Unsc.")
Set WS2 = Sheets("Print282")
LRow = LastRow(WS2)
Str = "282"
Call Copy_With_AutoFilter(WS, WS2, Str, LRow)
End Sub
----------------------------------------------------------------------------
----------------
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("B1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
----------------------------------------------------------------------------
------
Sub Copy_With_AutoFilter(WS As Worksheet, WS2 As Worksheet, Str As String,
LRow As Long)
With WS.Columns("b:b")
.AutoFilter Field:=1, Criteria1:=Str
WS.Range("D:F").Cells.SpecialCells(xlCellTypeVisible).Copy _
WS2.Range("B" & LRow )
End With
WS.AutoFilterMode = False
End Sub
put them on two diferent sheets column b is either the number 281 or 282. I
want them on "Print281" and "Print282".
They should be appending the print sheets. be they seem to be replacing
instead. Can anyone help??
----------------------------------------------------------------------------
--------------
Private Sub btnProcess_Click()
Dim WS As Worksheet
Dim WS2 As Worksheet
Dim Str As String
Dim LRow As Long
Set WS = Sheets("lod")
Set WS2 = Sheets("Print282")
LRow = LastRow(WS2)
Str = "282"
Call Copy_With_AutoFilter(WS, WS2, Str, LRow)
Set WS = Sheets("lod")
Set WS2 = Sheets("Print281")
LRow = LastRow(WS2)
Str = "281"
Call Copy_With_AutoFilter(WS, WS2, Str, LRow)
Set WS = Sheets("Unsc.")
Set WS2 = Sheets("Print281")
LRow = LastRow(WS2)
Str = "281"
Call Copy_With_AutoFilter(WS, WS2, Str, LRow)
Set WS = Sheets("Unsc.")
Set WS2 = Sheets("Print282")
LRow = LastRow(WS2)
Str = "282"
Call Copy_With_AutoFilter(WS, WS2, Str, LRow)
End Sub
----------------------------------------------------------------------------
----------------
Function LastRow(sh As Worksheet)
On Error Resume Next
LastRow = sh.Cells.Find(What:="*", _
After:=sh.Range("B1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row
On Error GoTo 0
End Function
----------------------------------------------------------------------------
------
Sub Copy_With_AutoFilter(WS As Worksheet, WS2 As Worksheet, Str As String,
LRow As Long)
With WS.Columns("b:b")
.AutoFilter Field:=1, Criteria1:=Str
WS.Range("D:F").Cells.SpecialCells(xlCellTypeVisible).Copy _
WS2.Range("B" & LRow )
End With
WS.AutoFilterMode = False
End Sub