+ Reply to Thread
Results 1 to 4 of 4

Adapt VBA code to Copy only cells with Data

Hybrid View

  1. #1
    Forum Contributor
    Join Date
    08-07-2014
    Location
    London
    MS-Off Ver
    10
    Posts
    148

    Adapt VBA code to Copy only cells with Data

    Hi all,

    I was wondering if someone could help me out with this. I have the below code, which I'd like to adapt. At the moment it copies all data from cells A2:E500. However, what I'd like it to do is copy only the cells with data in those columns, so basically select and copy only the cells with data in it. So for example if the data only goes down to A20 then I only want it to copy A2:E20 and not A2:E500.

    Can someone help!

    Dim lst As Long
    
    Sheets("Email Check").Range("A:E").Copy
    
    With Sheets("KYC to Check")
        lst = .Range("A" & Rows.Count).End(xlUp).Row + 1
        .Range("A" & lst).PasteSpecial xlPasteColumnWidths
        .Range("A" & lst).PasteSpecial xlPasteValues
    Thanks!
    Last edited by ShakJames; 09-29-2016 at 11:41 AM.

  2. #2
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Adapt VBA code to Copy only cells with Data

    Maybe:

    Sub ShakJames()
    Dim x As Long
    With Sheets("Email Check")
    x = .Range("A2").End(xlDown).row
        .Range("A2:E" & x).Copy
    End With
    End Sub

  3. #3
    Forum Contributor
    Join Date
    08-07-2014
    Location
    London
    MS-Off Ver
    10
    Posts
    148

    Re: Adapt VBA code to Copy only cells with Data

    Cheers, John

    That's done that job.

    Thanks for the help. Much appreciated.

  4. #4
    Forum Expert
    Join Date
    06-12-2012
    Location
    Ridgefield Park, New Jersey
    MS-Off Ver
    Excel 2003,2007,2010
    Posts
    10,241

    Re: Adapt VBA code to Copy only cells with Data

    You're welcome. Glad to help out and thanks for the feedback.

+ 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. [SOLVED] Adapt my current VBA Code to update pivot based selection in 2 cells
    By michelle 1 in forum Excel Charting & Pivots
    Replies: 0
    Last Post: 08-24-2015, 03:34 AM
  2. [SOLVED] Adapt Code to copy and paste multiple Ws to multiples Ws to another Wb
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 11
    Last Post: 08-13-2015, 11:42 AM
  3. adapt VBA code to stop and alert if any cells are blank
    By yachrishere in forum Excel Programming / VBA / Macros
    Replies: 7
    Last Post: 08-01-2014, 06:52 AM
  4. How to adapt this code to copy unique values in cells
    By RayJay01 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 03-02-2014, 07:18 AM
  5. [SOLVED] How to adapt a code to include a range of cells instead of the whole sheet
    By nje in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 10-08-2013, 08:52 AM
  6. [SOLVED] Adapt VBA code to clear the related cells instead of update
    By michelle 1 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 07-26-2013, 05:50 AM
  7. [SOLVED] Adapt code to copy and paste
    By marreco in forum Excel Programming / VBA / Macros
    Replies: 4
    Last Post: 05-09-2012, 07:52 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