+ Reply to Thread
Results 1 to 7 of 7

Copy paste column

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Question Copy paste column

    Hi, all

    I have this one file where I need to copy paste the filled cells in column A in a table from Sheet Raw data to column A in MB.

    This is quite simple though hence I already wrote one short code.

    But it shows application-defined or object-defined error.

    Sub main()
        Dim r As Range
    
        Set r = ActiveWorkbook.Sheets("Raw Data").Range("A")
        Do While r.Value <> ""
            ActiveWorkbook.Sheets("MB").Range("A").Value = r.Value
            Set r = r.Offset(1)
        Loop
    End Sub
    Is it because I'm dealing with a table instead of cells? Hope anyone can enlighten me. Thanks!
    Attached Files Attached Files

  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: Copy paste column

    If I understand the request why not just use the single line of code

    Sheet1.Range("A1").CurrentRegion.Offset(1, 0).Copy Destination:=Sheet2.Range("A2")
    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
    Forum Contributor tax112's Avatar
    Join Date
    02-28-2013
    Location
    Thailand
    MS-Off Ver
    Excel 2016 | 2019
    Posts
    442

    Re: Copy paste column

    Try:
    Sub Test()
    With Sheets("Raw data")
       .Range("A2", .Range("A" & Rows.Count).End(xlUp)).SpecialCells(xlVisible).Copy Sheets("MB").Range("A2:A" & Cells(Rows.Count, "A").End(xlUp).Row + 1)
    End With
    End Sub

  4. #4
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Copy paste column

    Hi, tax112

    Your code can be ran but nothing came out, not sure why though? A pop-out box came out which says Do you want to replace the content of destination cells although it's already empty.

    Update: and now it currently shows error: subscript out of range

    Hi, Richard

    Your code shows error: Object required, not sure why either.
    Last edited by ell_; 04-11-2019 at 10:28 PM.

  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: Copy paste column

    Quote Originally Posted by ell_ View Post
    Hi, tax112

    Your code can be ran but nothing came out, not sure why though? A pop-out box came out which says Do you want to replace the content of destination cells although it's already empty.

    Update: and now it currently shows error: subscript out of range

    Hi, Richard

    Your code shows error: Object required, not sure why either.
    You'll need to upload the workbook in which you've entered the code I gave you and explain exactly what you do. Have you changed something else perhaps.

    Add an additional line of code before the code I gave of

    Application.DisplayAlerts = False
    That will presumably fix it but it would be good to know why you get the warning in the first place.

  6. #6
    Forum Contributor tax112's Avatar
    Join Date
    02-28-2013
    Location
    Thailand
    MS-Off Ver
    Excel 2016 | 2019
    Posts
    442

    Re: Copy paste column

    Please press the button
    Attached Files Attached Files

  7. #7
    Forum Contributor
    Join Date
    09-19-2017
    Location
    London
    MS-Off Ver
    2015
    Posts
    169

    Re: Copy paste column

    Hi, tax112

    Thank you so much. It works now.

    Hi Richard,

    Thank you for the solution, it works as well.

+ 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: 02-28-2018, 09:40 AM
  2. Replies: 0
    Last Post: 10-29-2015, 04:15 PM
  3. Replies: 1
    Last Post: 05-30-2015, 04:38 PM
  4. How do I make the copy/paste of one column contingent on the copy/paste of another?
    By Kwasimitsu in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 01-23-2014, 01:51 PM
  5. Replies: 3
    Last Post: 05-22-2013, 01:08 AM
  6. Vba - find next empty column, insert column, copy paste values & copy paste formulas
    By DoodlesMama in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 12-20-2012, 12:43 PM
  7. Save column J only using copy/paste & temporary copy
    By mikeburg in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 06-07-2006, 12:37 PM

Tags for this Thread

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