你能帮我解决这个小问题吗:让我解释一下我有一个包含多张工作表的工作簿
过滤苹果表列A结果一一复制几列粘贴到相应列中的相应给定表
并且同样需要为橙色结果一一复制几列粘贴到相应列中的相应给定工作表:这里它正在替换从Apple工作表复制的数据
您能否在粘贴时帮助我数据应该考虑该列的最后一行,我尝试了所有可能的方法仍然数据被替换
'Assign and set your variables
Sub data()
'Application.ScreenUpdating = False
'Application.CutCopyMode = True
'Declare variable and give sheet names
Dim ws1 As Worksheet, ws2 As Worksheet, ws3 As Worksheet, ws4 As Worksheet, lRow As Long, lastrow As Long
' for example am showing only two sheet actualy i have lot of sheets here ( i dont know how it can be loop)
Set ws1 = ThisWorkbook.Sheets("A")
Set ws2 = ThisWorkbook.Sheets("B")
Set ws3 = ThisWorkbook.Sheets("Apple")
Set ws4 = ThisWorkbook.Sheets("Orange")
'Declare for last row
Dim InputBox As String
lRow = ws1.Cells(ws1.Rows.Count, 1).End(xlUp).Row
lastrow = ws3.Cells(ws3.Rows.Count, 10).End(xlUp).Row
'Apple and orange sheet name header start from 4th row
Sheets("Apple").Select
Rows("4:36" & lRow).Clear
Sheets("Orange").Select
Rows("4:36" & lRow).Clear
With ws1
.Range("A1:Q1").AutoFilter Field:=1, Criteria1:="apple"
.Range("J2").Resize(lRow - 1).SpecialCells(xlCellTypeVisible).Copy Destination:=ws3.Range("c4")
.Range("P2").Resize(lRow - 1).SpecialCells(xlCellTypeVisible).Copy Destination:=ws3.Range("L4")
.Range("Q2").Resize(lRow - 1).SpecialCells(xlCellTypeVisible).Copy Destination:=ws3.Range("K4")
.Range("A1").AutoFilter 'clear the filter
.Range("A1:Q1").AutoFilter Field:=1, Criteria1:="orange"
.Range("J2").Resize(lRow - 1).SpecialCells(xlCellTypeVisible).Copy Destination:=ws4.Range("c4")
.Range("P2").Resize(lRow - 1).SpecialCells(xlCellTypeVisible).Copy Destination:=ws4.Range("L4")
.Range("Q2").Resize(lRow - 1).SpecialCells(xlCellTypeVisible).Copy Destination:=ws4.Range("K4")
.Range("A1").AutoFilter 'clear the filter
End With
'Below am not getting low row and while paste ( it is replacing old data)
With ws2
.Range("A1:S1").AutoFilter Field:=2, Criteria1:="apple"
.Range("H2").Resize(lRow - 1).SpecialCells(xlCellTypeVisible).Copy Destination:=ws3.Range("K5" & lastrow)
.Range("I2").Resize(lRow - 1).SpecialCells(xlCellTypeVisible).Copy Destination:=ws3.Range("L4")
.Range("S2").Resize(lRow - 1).SpecialCells(xlCellTypeVisible).Copy Destination:=ws3.Range("C4")
.Range("B1").AutoFilter 'clear the filter
.Range("A1:S1").AutoFilter Field:=2, Criteria1:="Orange"
.Range("H2").Resize(lRow - 1).SpecialCells(xlCellTypeVisible).Copy Destination:=ws4.Range("K4")
.Range("I2").Resize(lRow - 1).SpecialCells(xlCellTypeVisible).Copy Destination:=ws4.Range("L4")
.Range("S2").Resize(lRow - 1).SpecialCells(xlCellTypeVisible).Copy Destination:=ws4.Range("C4")
.Range("B1").AutoFilter 'clear the filter
End With
End Sub