Below is part of the code to copy a range from sheet "Template" and paste to the first blank Row on the Active Sheet. Row 1 is the Header Row.
What I am wanting to do is reference the just pasted rows in order to then Group
the Rows.
My VBA is poor and I am unsure how to correctly set "PastedRange". How could I achieve this?
Dim copySheet As Worksheet
Dim pasteSheet As Worksheet
Dim LRow As Long
Dim PastedRange As Range
Set copySheet = ThisWorkbook.Worksheets("Template")
Set pasteSheet = ThisWorkbook.ActiveSheet
Set PastedRange = .Range("A" & .Rows.Count).End(xlUp).Row
With pasteSheet
'~~> Find the last cell to write to
If Application.WorksheetFunction.CountA(.Cells) = 0 Then
LRow = 2
Else
LRow = .Range("A" & .Rows.Count).End(xlUp).Row + 1
End If
copySheet.Range("2:" & copySheet.Cells(Rows.Count, _
1).End(xlUp).Row).Copy
.Rows(LRow).PasteSpecial Paste:=xlPasteAll
PastedRange.Group
End With
PastedRange
and.Range("A" & .Rows.Count).End(xlUp).Row
must be included inWith something
andEnd With
. Also, you assign value toLRow
only. What do you want to paste? Please provide your desired sample and corresponding result – GGGSet PastedRange = .Range("A" & .Rows.Count).End(xlUp).Row
, in the place where it exists, will raise an error. It cannot return anything with that used construction (.Range(...
), from two points of view: The line returns a row instead of a range, and .Range(...` has a meaning only inside aWith SomeSheet
followed by your code andEnd With
. – FaneDuruPastedRange = .Range("A" & .Rows.Count).End(xlUp)
andPastedRange.Group
just before End With. Is this the correct way to do it? The grouping hasn't worked. – aye cee