View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Toppers Toppers is offline
external usenet poster
 
Posts: 4,339
Default Copying a variable selection size ?

Hi,
This copies data from A2 onwards on Sheet1 to C2 (starting cell) on
Sheet2. Change as required.


HTH

Sub CopyRange()

Dim ws1 As Worksheet, ws2 As Worksheet
Dim dstrng As Range
Dim lastrow As Long

Set ws1 = Worksheets("Sheet1")
Set ws2 = Worksheets("Sheet2")
Set dstrng = ws2.Range("C2")

With ws1
lastrow = .Cells(Rows.Count, "A").End(xlUp).Row
.Range("A2:A" & lastrow).Copy dstrng
End With
End Sub

"CPhil" wrote:


Can someone please enlighten with a solution to this:

When I'm writing a macro in VBA and for instance I need to copy a set
of data from one place to another. - however, each time it will be run,
the number of rows of the data that is different - How can I select
just that data ??

Hope that makes sense!


--
CPhil
------------------------------------------------------------------------
CPhil's Profile: http://www.excelforum.com/member.php...o&userid=29842
View this thread: http://www.excelforum.com/showthread...hreadid=495471