我有第1张(格式化为表格)和第2张(格式化为表格)。我想将活动行从第1页复制到第2页。我已尝试过以下内容,它适用于正常范围,但不适用于格式化为表格的工作表。
Private Sub CommandButton1_Click()
Dim lastrow As Long
With ThisWorkbook.Worksheets("Sheet2")
lastrow = Application.Max(4, .Cells(.Rows.Count, "B").End(xlUp).Row + 1)
.Range("B" & lastrow).Resize(, 5).Value = _
Range("A" & ActiveCell.Row).Resize(, 5).Value
End With
End Sub
答案 0 :(得分:1)
<强>更新强>
Private Sub CommandButton1_Click()
Dim tbl As ListObject
Dim tblRow As ListRow
Dim lastRow As Long
If UCase(Range("F" & ActiveCell.Row)) <> "YES" Then Exit Sub
With ThisWorkbook.Worksheets("Sheet3")
'change Sheet3 to destination sheet - where you need to paste values
If Not IsError(Application.Match(Range("B" & ActiveCell.Row), .Range("B:B"), 0)) Then Exit Sub
Set tbl = .ListObjects(1)
If tbl.Range(tbl.Range.Rows.Count, "B") = "" Then
lastRow = Application.Min(tbl.Range(tbl.Range.Rows.Count, "B").End(xlUp).Row + 1, _
Application.Max(4, .Cells(.Rows.Count, "B").End(xlUp).Row + 1))
Else
lastRow = tbl.ListRows.add.Range.Row
End If
End With
tbl.Range(lastRow, "B").Resize(, 5).Value = _
Range("A" & ActiveCell.Row).Resize(, 5).Value
End Sub