以下代码正常。但是,我需要从列中的特定行开始粘贴数据。根据代码,我可以将数据粘贴到列C' C'但如果我想从C5'开始粘贴例如,我如何更改编码?谢谢您的帮助。
Private Sub CommandButton1_Click()
Dim sh As Worksheet
Dim rData As Range, rCell As Range, rFrom As Range, rTo As Range
Dim lRightCol As Long
Dim ass As Integer
ass = 4
With ActiveSheet
lRightCol = .Range("C3").Column
Set rData = .Range(.Range("A3"), .Range("D" & .Rows.Count).End(xlUp))
For Each rCell In rData
Set sh = Nothing
On Error Resume Next
Set sh = Worksheets(rCell.Value)
On Error GoTo 0
If Not sh Is Nothing Then
Set rFrom = rCell.Resize(1, lRightCol)
With sh
Set rTo = .Range("C" & .Rows.Count).End(xlUp).Offset(1).Resize(1, lRightCol)
End With
rFrom.Copy rTo
End If
Next rCell
End With
End Sub
我尝试将代码更改为以下但无法正常工作。
Set rTo = .Range("C5" & .Rows.Count).End(xlUp).Offset(1).Resize(1, lRightCol)
答案 0 :(得分:1)
正如我在评论中提到的那样。你可以使用:
Set rTo = .Range("C" & Application.Max(5,.Cells(.Rows.Count,"C").End(xlUp).Row + 1))