+ Reply to Thread
Results 1 to 4 of 4

copy and paste a range of cells to the left

  1. #1
    Registered User
    Join Date
    06-03-2010
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    3

    copy and paste a range of cells to the left

    Hi all, I am new to writing up code in VBA. i am trying to copy cells on a range and paste them to the left into colums A to D. the maro runs but it get rid every second existing raw. This is what I am doing (see the picture), and the code is:

    Sub CopyPaste()

    Dim I As Long, LastLine As Long
    Dim R As Integer

    Sheets(2).Activate
    LastLine = Cells(Rows.Count, "A").End(xlUp).Row

    R = 0
    For I = R + 2 To LastLine
    Sheets(2).Range("G" & I & ":J" & I).Copy
    Range("A" & I & ":D" & I).PasteSpecial
    R = R + 2
    Next

    MsgBox "Done"
    End Sub

    I would appreciate if someone can can point me in the right direction, thanks heaos!
    Attached Images Attached Images
    Last edited by michaelram; 06-03-2010 at 09:19 PM.

  2. #2
    Forum Contributor
    Join Date
    12-03-2009
    Location
    Providence RI
    MS-Off Ver
    Excel 2007, Excel 2010
    Posts
    260

    Re: copy and paste a range of cells to the left

    Hello and welcome to the forums. Please review the forum rules and place code tags around your code.

    3. Use code tags around code. Posting code without them makes your code hard to read and difficult to be copied for testing. Highlight your code and click the # button at the top of the post window. If you are editing an existing post, press Go Advanced to see the # button. For more information about these and other tags, click here.

  3. #3
    Registered User
    Join Date
    06-03-2010
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: copy and paste a range of cells to the left

    Please Login or Register  to view this content.

  4. #4
    Registered User
    Join Date
    06-03-2010
    Location
    Sydney
    MS-Off Ver
    Excel 2003
    Posts
    3

    Re: copy and paste a range of cells to the left

    [QUOTE=michaelram;2318800][CODE]
    Sub CopyPaste()

    Dim I As Long, LastLine As Long
    Dim R As Integer

    Sheets(2).Activate
    LastLine = Cells(Rows.Count, "A").End(xlUp).Row

    R = 0
    For I = R + 2 To LastLine
    Sheets(2).Range("G" & I & ":J" & I).Copy
    Range("A" & I & ":D" & I).PasteSpecial
    R = R + 2
    Next

    MsgBox "Done"
    End Sub


    I got rid of the R=R + 2
    and added at the end of For I = R + 2 To LastLine step 2
    This seams to work but there is one little problem, there are some cell that end up highlighted. How can I eliminate that?, thanks

+ 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