+ Reply to Thread
Results 1 to 3 of 3

Copying a variable selection size ?

  1. #1
    Registered User
    Join Date
    12-22-2005
    Posts
    7

    Copying a variable selection size ?

    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!

  2. #2
    Toppers
    Guest

    RE: 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
    >
    >


  3. #3
    Registered User
    Join Date
    12-22-2005
    Posts
    7
    thanks for the info - worked a treat

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1