+ Reply to Thread
Results 1 to 6 of 6

Code to copy data from sheet1 to sheet2 the first time, and then update after that

  1. #1
    Registered User
    Join Date
    01-28-2014
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    50

    Smile Code to copy data from sheet1 to sheet2 the first time, and then update after that

    Hi
    I'm very new to all of this VBA work and am a bit stuck - I have been googling lots of information and this site has provided me with loads of help, but now I need more!

    I have a spreadsheet where I wanted to copy 5 columns of data in sheet 1, into 1 column in sheet2. I have managed to do some coding for this (probably a very long winded way around) and the data copies through to sheet2 with no problems. This is the code I've used:

    Sub CopyData()
    Sheets("WBS - High Level").Range("B4:C20").Copy _
    Sheets("WBS - Explanation").Cells(Rows.Count, 1).End(xlUp).offset(1, 0)
    Sheets("WBS - Explanation").Select
    Sheets("WBS - High Level").Range("E4:F20").Copy _
    Sheets("WBS - Explanation").Cells(Rows.Count, 1).End(xlUp).offset(1, 0)
    Sheets("WBS - Explanation").Select
    Sheets("WBS - High Level").Range("H4:I20").Copy _
    Sheets("WBS - Explanation").Cells(Rows.Count, 1).End(xlUp).offset(1, 0)
    Sheets("WBS - Explanation").Select
    Sheets("WBS - High Level").Range("K4:L20").Copy _
    Sheets("WBS - Explanation").Cells(Rows.Count, 1).End(xlUp).offset(1, 0)
    Sheets("WBS - Explanation").Select
    Sheets("WBS - High Level").Range("N4:O20").Copy _
    Sheets("WBS - Explanation").Cells(Rows.Count, 1).End(xlUp).offset(1, 0)
    Sheets("WBS - Explanation").Select
    Sheets("WBS - High Level").Range("Q4:R20").Copy _
    Sheets("WBS - Explanation").Cells(Rows.Count, 1).End(xlUp).offset(1, 0)
    Sheets("WBS - Explanation").Select
    Sheets("WBS - High Level").Range("T4:U20").Copy _
    Sheets("WBS - Explanation").Cells(Rows.Count, 1).End(xlUp).offset(1, 0)
    Sheets("WBS - Explanation").Select
    Sheets("WBS - High Level").Range("W4:X20").Copy _
    Sheets("WBS - Explanation").Cells(Rows.Count, 1).End(xlUp).offset(1, 0)
    Sheets("WBS - Explanation").Select
    End Sub

    However, if I make changes to sheet1, I can't get the information to update in sheet2 without everything in sheet1 being copied into sheet 2 after the original copy (hope that makes sense!). Can someone help me please!
    Thanks

  2. #2
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Code to copy data from sheet1 to sheet2 the first time, and then update after that

    What are you trying to do?
    copy sheet1 data into 1 column of sheet 2,
    then
    do you want to clear sheet 2 and then copy sheet1 again?

    if you want to clear sheet 2 first then add
    Please Login or Register  to view this content.
    at the start of your code.
    Regards
    Sean

    Please add to my reputation if you think i helped
    (click on the star below the post)
    Mark threads as "Solved" if you have your answer
    (Thread Tools->Mark thread as Solved)
    Use code tags when posting your VBA code:
    [code] Your code here [code]
    Please supply a workbook containing example Data:
    It makes its easier to answer your problem & saves time!

  3. #3
    Registered User
    Join Date
    01-28-2014
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Code to copy data from sheet1 to sheet2 the first time, and then update after that

    Hi Sean
    Thanks for such a quick respons!

    The code works, however, it causes me to lose information in rows 1-3 in the WBS - Explanation sheet, which I need to keep. Is there something I can add to only clear rows 4-200 in columns A and B in the WBS - Explanation sheet?

    Thanks
    Emma

  4. #4
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Code to copy data from sheet1 to sheet2 the first time, and then update after that

    try
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    01-28-2014
    Location
    Dunedin, New Zealand
    MS-Off Ver
    Excel 2010
    Posts
    50

    Re: Code to copy data from sheet1 to sheet2 the first time, and then update after that

    That is just amazing Sean, it works perfectly, thanks so much for your help!!

  6. #6
    Valued Forum Contributor Sean Thomas's Avatar
    Join Date
    03-25-2012
    Location
    HerneBay, Kent, UK
    MS-Off Ver
    Excel 2007,2016
    Posts
    971

    Re: Code to copy data from sheet1 to sheet2 the first time, and then update after that

    Glad to help
    don't forget to add reputation & mark thread as solved

+ Reply to Thread

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Replies: 6
    Last Post: 07-25-2013, 02:58 PM
  2. [SOLVED] VBA code for not copy data in Sheet2 if all cells in range in Sheet1 are not filled
    By ginodauri in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 07-10-2013, 12:33 PM
  3. Refine Code to Copy Row From Sheet1 to Sheet2
    By berkley in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 10-31-2010, 11:07 AM
  4. code tweak to copy data from sheet1 to sheet2
    By imatomic in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-28-2010, 02:18 PM
  5. how to update data on sheet1 and have it auto update on sheet2
    By Tommy in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 05-11-2005, 06:43 PM

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