+ Reply to Thread
Results 1 to 3 of 3

copying data from one sheet to another in different columns

Hybrid View

  1. #1
    Registered User
    Join Date
    12-21-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    21

    copying data from one sheet to another in different columns

    Hi Guys

    I am new to VBA trying to create a macro to copy some data from sheet2 (we can have any number of rows in this data it’s not fixed) and paste it to sheet1. Attached is sample data file. I need to copy data from sheet 2 to sheet1.

    Data from column A to C (sheet2) needs to go to first empty cells in column C to E (sheet 1)
    Data from column G to N (sheet2) needs to go to first empty cells in column I to P (sheet 1)
    Data from column AC (sheet2) needs to go to first empty cells in column A E (sheet 1)
    And then in (A, B & Q to AD) columns copy and paste the formula from above cells.

    Just to explain a little more data in sheet2 didn’t had any blank columns actually I inserted these blank columns to match it with sheet1 I thought that might help in copy paste using below code but it isn’t working, any help would be much appreciated:

    Sub copydata()
    Dim lr, lc
    lr = Sheets("sheet2").Cells(Rows.Count, 29).End(xlUp).Row
    lc = Sheets("sheet1").Cells(Rows.Count, 1).End(xlUp).Offset(1).Row
    Sheets("sheet2").Range("A2:AC" & lr).Copy Destination:=Sheets("sheet1").Cells(lc, 3)
    End Sub
    Attached Files Attached Files

  2. #2
    Forum Expert
    Join Date
    03-28-2012
    Location
    TBA
    MS-Off Ver
    Office 365
    Posts
    12,454

    Re: copying data from one sheet to another in different columns

    Try this one

    Sub copyme()
    
        Set ms = Sheets("sheet1")
        
        With Sheets("sheet2")
             LR = .Cells.Find("*", , , , xlByRows, xlPrevious).Row
            .Range("A2:C" & LR).Copy ms.Range("C" & Rows.Count).End(xlUp).Offset(1)
            .Range("G2:N" & LR).Copy ms.Range("I" & Rows.Count).End(xlUp).Offset(1)
            .Range("AC2:AC" & LR).Copy ms.Range("AE" & Rows.Count).End(xlUp).Offset(1)
             LR1 = ms.Range("A:Z").Find("*", , , , xlByRows, xlPrevious).Row
             ms.Range("A2:B2").AutoFill Destination:=ms.Range("A2:B" & LR1)
             ms.Range("Q2:AD2").AutoFill Destination:=ms.Range("Q2:AD" & LR1)
        End With
        Set ms = Nothing
    End Sub

  3. #3
    Registered User
    Join Date
    12-21-2012
    Location
    London
    MS-Off Ver
    Excel 2007
    Posts
    21

    Re: copying data from one sheet to another in different columns

    many thanks for your help mate.
    my code also working now i am not sure why it didn't worked first time.

+ 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