我想将行(A:E),行(F:AH)和行(AL)从活动工作簿复制到行(A:E),行(G:AI),另一个工作簿的行(AJ)。这是我正在处理的代码。我在这里看到它,然后编辑它。基于单元值将特定行复制到另一个工作簿
Dim wb1 As Workbook, wb2 As Workbook
Dim ws1 As Worksheet, ws2 As Worksheet
Dim copyFrom As Range
Dim lRow As Long
Dim strSearch As String
Dim ret
ret = Application.GetOpenFilename(FileFilter:="Excel Workbooks (*.xls, .xlsx*),*.xls, .xlsx*", _
Title:="Select data file for Monitoring Log")
Set wb1 = ThisWorkbook
Set ws1 = wb1.Worksheets("Macro Template")
strSearch = "Newly Distributed"
With ws1
.AutoFilterMode = False
lRow = .Range("AL" & .Rows.Count).End(xlUp).Row
With .Range("AL7:AL" & lRow)
.AutoFilter Field:=1, Criteria1:="=*" & strSearch & "*"
Set copyFrom = .Offset(1, 0).SpecialCells(xlCellTypeVisible).EntireRow
End With
'~~> Remove any filters
.AutoFilterMode = False
End With
'~~> Destination File
Set wb2 = Application.Workbooks.Open(ret)
Set ws2 = wb2.Worksheets("Source")
With ws2
If Application.WorksheetFunction.CountA(.Cells) <> 0 Then
lRow = .Cells.Find(What:="*", _
After:=.Range("A1"), _
Lookat:=xlPart, _
LookIn:=xlFormulas, _
SearchOrder:=xlByRows, _
SearchDirection:=xlPrevious, _
MatchCase:=False).Row + 1
Else
lRow = 1
End If
copyFrom.Copy .Rows(lRow)
End With
wb2.Save
wb2.Close
此代码复制整个行。我如何修改它以复制特定的行。
的问题是不明确的。您似乎在某些点上使用“行”来表示“列”。请发布示例输入数据和预期输出。 –
我的错误是,列a:e中的数据将被复制到另一个工作簿的列a:e中。我不想使用整行,而是想从行的列中复制选定的数据。 –