Help with copying data from multiple sheets to multiple sheets

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

------------------
 
R

Randy Reese

I think you may had posted this by error.

Ajit said:
Give it a shot

Go to tools ==> Macros==> security ==>trusted sources tab ==> and check
"Trust Access to Visual Basic Project"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top