View Single Post
  #5   Report Post  
Posted to microsoft.public.excel.programming
Mike H Mike H is offline
external usenet poster
 
Posts: 11,501
Default Select all rows till last row with value in Column A and CopyP

oops,

use this instead

Sub Copy()
Dim LastrowA As Long
Dim LastrowB As Long
Set SrcSht = Sheets("Sheet1")
Set DstSht = Sheets("Sheet2")
LastrowA = SrcSht.Cells(Cells.Rows.Count, "A").End(xlUp).Row
LastrowB = DstSht.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
SrcSht.Range("A1:A" & LastrowA).EntireRow.Copy DstSht.Cells(LastrowB, 1)
End Sub
--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"Mike H" wrote:

Hi,

How about this. Note we've got rid of any need to select ranges.

Sub Copy()
Dim LastrowA As Long
Dim LastrowB As Long
Set SrcSht = Sheets("Sheet1")
Set DstSht = Sheets("Sheet2")
LastrowA = SrcSht.Cells(Cells.Rows.Count, "A").End(xlUp).Row
LastrowB = DstSht.Cells(Cells.Rows.Count, "A").End(xlUp).Row + 1
Range("A1:A" & LastrowA).EntireRow.Copy DstSht.Cells(LastrowB, 1)
End Sub

--
Mike

When competing hypotheses are otherwise equal, adopt the hypothesis that
introduces the fewest assumptions while still sufficiently answering the
question.


"PVANS" wrote:

Good morning

Was wondering whether someone could help me with this.
I am trying to select all rows up until the last row with a value in column
A on Worksheet1, copy this selection, and paste it into the (last row + 1) in
Worksheet 2. Initially I was going to use this code below (as I know that
the total number of lines on sheet1 will never exceed 250):

Sub Copy()

Dim Lastrow As Long

Sheets("Sheet1").Select
Rows("1:250").Select
Selection.Copy
Sheets("Sheet2").Select
Lastrow = Cells(Cells.Rows.Count, "A").End(xlUp).Row
Cells(Lastrow + 1, 1).Select
Selection.Paste

End Sub

I get the following error:
Run-time error '438':
Object doesn't support this property or method

Please can someone assist? (also, whilst the code above simply selects
columns1:250, if I could select up until the last row with data in column A,
I would prefer that)

Thanks so much for the help