+ Reply to Thread
Results 1 to 5 of 5

Copy Range with variable

  1. #1
    Registered User
    Join Date
    11-27-2009
    Location
    NYC
    MS-Off Ver
    Excel 2007
    Posts
    25

    Unhappy Copy Range with variable


    Please Login or Register  to view this content.
    Sub

    I am trying to copy A1:G7 and paste it as transpose to say J1 ... I have 7 rows filled.. now I have to copy from A3-G9 and paste as J8 .. and like wise ..
    I am stuck at how to change the range with help of variables.
    my idea is
    for k = 1 to 100 step 2
    A[k]:G[k+1] ..
    how to write this piece with VBA ..

    Any help will be highly appreciated ..

    Thanks in advance

    Shammi
    Last edited by shammi_Raj; 11-27-2009 at 01:48 PM.

  2. #2
    Registered User
    Join Date
    11-27-2009
    Location
    NYC
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Copy Range with variable

    I found the solution to the problem . Incase anyone might need in future or I need to refer when my poor memory fails to recollect ..

    I used

    Please Login or Register  to view this content.
    The mistake I was making was - using ":" instead of "," in Range ..

  3. #3
    Forum Guru DonkeyOte's Avatar
    Join Date
    10-22-2008
    Location
    Northumberland, UK
    MS-Off Ver
    O365
    Posts
    21,531

    Re: Copy Range with variable

    Thank you for both

    a) adding tags

    and

    b) posting your solution

    On an aside you could use something like

    Please Login or Register  to view this content.
    disabling screen repaint and avoiding Select whilst running your routine will improve overall performance

  4. #4
    Registered User
    Join Date
    11-27-2009
    Location
    NYC
    MS-Off Ver
    Excel 2007
    Posts
    25

    Thumbs up Re: Copy Range with variable

    Thanks .. This solution is awesome .. like it

  5. #5
    Registered User
    Join Date
    11-27-2009
    Location
    NYC
    MS-Off Ver
    Excel 2007
    Posts
    25

    Re: Copy Range with variable

    Need further help on this .. anyone please

    I am able to select range with a variable as in

    k =2
    Range("A" & k, "G" & k + 1).Select

    but when I have to select from other sheet say ..

    Range("'Sheet5'!$A$2:$G$3")

    How do I go about it ? - My doubt is the syntax for selecting sheet and range in one line .

    something like this should help

    Range("'Sheet5'" & "A" & k, "G" & k + 1)
    Last edited by shammi_Raj; 02-17-2010 at 01:45 PM.

+ 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