Consulting

Results 1 to 4 of 4

Thread: Quick & Easy-

  1. #1

    Quick & Easy-

    This should be fairly simple, my brain is fried right now and I cant think of the simpler way:
    How can I change the following code into a for loop or a loop?

    'Ext- Destination Sheet
    'Sheet7 - Target Sheet
    'range("ExtRNG1")- predefined range in the target sheet with a given name
    'range("ExtRNG2")-->("ExtRNG9") - same as above
    I just need to copy each range and paste it in to the Ext sheet

    Sub extvalue()
    Sheets("Ext").Select
    Range("E15").Select
    Sheet7.Range("ExtRNG1").Copy
    Selection.PasteSpecial (xlPasteValues)
    Range("E65536").End(xlUp).Select
    ActiveCell.Offset(1, 0).Select
    Sheet7.Range("ExtRNG2").Copy
    Selection.PasteSpecial (xlPasteValues)
    Range("E65536").End(xlUp).Select
    ActiveCell.Offset(1, 0).Select
    Sheet7.Range("ExtRNG3").Copy
    Selection.PasteSpecial (xlPasteValues)
    Range("E65536").End(xlUp).Select
    ActiveCell.Offset(1, 0).Select
    end sub
    Thank you!!!!!

  2. #2
    Site Admin
    Jedi Master
    VBAX Guru Jacob Hilderbrand's Avatar
    Joined
    Jun 2004
    Location
    Roseville, CA
    Posts
    3,712
    Location
    Try something like this:


    For i = 1 To 3
    Sheet7.Range("ExtRNG" & i).Copy
        Range("E65536").End(xlUp).Offset(1, 0).PasteSpecial (xlPasteValues)
    Next i

  3. #3
    Site Admin
    Urban Myth
    VBAX Guru
    Joined
    May 2004
    Location
    Oregon, United States
    Posts
    4,940
    Location
    I don't understand why you want to use the Copy method - especially when using PasteValues!? VBA is great for transfering values without using the cumbersome Copy/Paste method. ..

    For i = 1 To 3 
        Range("E65536").End(xlUp).Offset(1) = Sheet7.Range("ExtRNG" & i).Value
    Next i

  4. #4
    Thank you soo much!! This works for me now!!

Posting Permissions

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