+ Reply to Thread
Results 1 to 6 of 6

Copying Columns from one sheet to another

  1. #1
    Registered User
    Join Date
    11-06-2014
    Location
    Uk
    MS-Off Ver
    2010
    Posts
    7

    Copying Columns from one sheet to another

    Hi there,

    I'm a complete VBA newbie. I've tried googling methods to copy columns across, but keep getting the compile expected end sub error. I've also found people recommending very different ways of doing it. I've tried searching this forum but didn't find precisely what I need.

    I'm literally just trying to copy columns say A, B, C in Sheet 1 to columns D, E F in Sheet 2.

    Many thanks.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Copying Columns from one sheet to another

    Hi, and welcome to the forum.

    Do the columns you're copying contain formulae and if so should they be pasted as formulae or as constant values?
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    11-06-2014
    Location
    Uk
    MS-Off Ver
    2010
    Posts
    7

    Re: Copying Columns from one sheet to another

    Ah yes, they are just values. I have just tried the following methods,

    "Sheets("Sheet1").Range("A1:B10").Copy
    'Activate the destination worksheet
    Sheets("Sheet2").Activate
    'Select the target range
    Range("E1").Select
    'Paste in the target destination
    ActiveSheet.Paste

    Application.CutCopyMode = False"


    AND


    Sheets("Sheet1").Range("A1:B10").Copy Destination:=Sheets("Sheet2").Range("E1")



    For both I am now receiving "Run-time error 9".


    Many thanks.

  4. #4
    Registered User
    Join Date
    11-06-2014
    Location
    Uk
    MS-Off Ver
    2010
    Posts
    7

    Re: Copying Columns from one sheet to another

    My apologies for wasting any of your time but I've managed to fix it, I realised the version 1 I had to put a range into "Range", a crazy revelation for me.

    Thank you for your time, and feel free to delete this useless thread for others.

    IP

  5. #5
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Copying Columns from one sheet to another

    Hi,

    Not quite sure which code you are using but as a general point try and avoid using sheet tab names in VBA code. They can be changed too easily by a user causing a macro which uses them to fall over.
    Use instead the VBA sheet CODE name.

  6. #6
    Registered User
    Join Date
    11-06-2014
    Location
    Uk
    MS-Off Ver
    2010
    Posts
    7

    Re: Copying Columns from one sheet to another

    Excellent point, how do I change the code so that it chooses the underlying sheet code?

    Edit: I should add that I tried the obvious, changing the code within the parentheses from the tab name to "Sheet7" etc to the following:

    Sheets("Sheet7").Range("Q2:Q65").Copy

    But it didn't like it, why?

    IP
    Last edited by IP AUM; 11-06-2014 at 06:14 AM.

+ 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. copying columns from one sheet to another
    By emilyloz in forum Excel Programming / VBA / Macros
    Replies: 25
    Last Post: 07-30-2013, 02:33 PM
  2. [SOLVED] copying data from one sheet to another in different columns
    By Abhi1687 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 02-27-2013, 05:19 PM
  3. [SOLVED] VBA copying columns from one sheet to another - error / help
    By Traviscon in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 06-18-2012, 02:09 PM
  4. Help with copying some columns of a row to a new sheet if 2 conditions are met
    By Jess777 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 09-24-2010, 04:43 PM
  5. Copying Columns and Pasting in New Sheet
    By Topdrop18 in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 02-01-2010, 11:34 AM

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