R
Randy Reese
This is the error I get:
Run-Time error '1004':
AutoFilter method of Range class failed
in Copy_With_AutoFilter2 with this line:
.AutoFilter Field:=2, Criteria1:=Str, Operator:=xlAnd
----------------------------------------------------------
and
Why won't Unsc. info find the last line of lod on Print281 sheet???
----------------------------------------------------------
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)
Set WS = Sheets("Shipping")
Set WS2 = Sheets("Print281")
LRow = LastRow(WS2)
Str = "281"
Call Copy_With_AutoFilter2(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
Here's my code:
Sub Copy_With_AutoFilter2(WS As Worksheet, WS2 As Worksheet, Str As String,
LRow As Long)
With WS.Columns("a:a")
.AutoFilter Field:=2, Criteria1:=Str, Operator:=xlAnd
.AutoFilter Field:=1, Criteria1:="a"
WS.Range("D:F").Cells.SpecialCells(xlCellTypeVisible).Copy _
WS2.Range("B" & LRow)
End With
WS.AutoFilterMode = False
End Sub
------------------
Run-Time error '1004':
AutoFilter method of Range class failed
in Copy_With_AutoFilter2 with this line:
.AutoFilter Field:=2, Criteria1:=Str, Operator:=xlAnd
----------------------------------------------------------
and
Why won't Unsc. info find the last line of lod on Print281 sheet???
----------------------------------------------------------
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)
Set WS = Sheets("Shipping")
Set WS2 = Sheets("Print281")
LRow = LastRow(WS2)
Str = "281"
Call Copy_With_AutoFilter2(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
Here's my code:
Sub Copy_With_AutoFilter2(WS As Worksheet, WS2 As Worksheet, Str As String,
LRow As Long)
With WS.Columns("a:a")
.AutoFilter Field:=2, Criteria1:=Str, Operator:=xlAnd
.AutoFilter Field:=1, Criteria1:="a"
WS.Range("D:F").Cells.SpecialCells(xlCellTypeVisible).Copy _
WS2.Range("B" & LRow)
End With
WS.AutoFilterMode = False
End Sub
------------------