+ Reply to Thread
Results 1 to 18 of 18

VBA - Copy and paste only the cells with values

  1. #1
    Forum Contributor
    Join Date
    04-09-2014
    Location
    Derby
    MS-Off Ver
    Office 2013 - For my sins
    Posts
    122

    VBA - Copy and paste only the cells with values

    Hi Everyone,

    Hoping for another gem to help me.

    I have data in Cells K:2 to L:13 in which the length will never change but the values in column L will - This is on sheet "Aged Grid"

    Currently the data copies across to sheet "DeleteZeros" and then removes the blanks perfectly. What I now need is on the "DeleteZeros" sheet a macro that only copies cells with values from B2 all the way down to the next blank cell in column C, then pastes them back into the "Aged Grid" sheet under the next blank cell in column B - I've attached the spreadsheet so this all makes sense.

    Thank you in advance!!!!

    Frank
    Attached Files Attached Files
    Last edited by Frankinstyyn; 09-09-2016 at 05:21 PM.

  2. #2
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,870

    Re: VBA - Copy and paste only the cells with values

    I have data in Cells K:2 to L:13 in which the length will never change but the values in column L will - This is on sheet "Aged Grid"
    There is no data in these cells on this sheet

    What I now need is on the "DeleteZeros" sheet a macro that only copies cells with values from B2 all the way down to the next blank cell in column C
    In your example are we copying B2:C7 even though there are errors in two of the cells?
    then pastes them back into the "Aged Grid" sheet under the next blank cell in column B
    Paste to B26?

    Please clarify as I am a bit confused by your explanation and the worksheet shown. They don't quite seem to correlate.

    If you use your worksheet and explain which cells in your example and where they should go it would help to understand what you are asking.
    Alan עַם יִשְׂרָאֵל חַי


    Change an Ugly Report with Power Query
    Database Normalization
    Complete Guide to Power Query
    Man's Mind Stretched to New Dimensions Never Returns to Its Original Form

  3. #3
    Forum Contributor
    Join Date
    04-09-2014
    Location
    Derby
    MS-Off Ver
    Office 2013 - For my sins
    Posts
    122

    Re: VBA - Copy and paste only the cells with values

    Hi Alan,

    Thanks for getting back to me.

    Apologies it's unclear. I've deleted some data as it had personal stuff.

    To clarify:

    The errors don't really matter too much - they've been sorted now though.

    K:2 to L13 have data but they're already copied across.

    To copy back to Aged Grid, in this case it would be B4

    I've also updated the spreadsheet with instructions, I hope this helps as well.

    I hope that makes more sense.

  4. #4
    Forum Contributor
    Join Date
    04-09-2014
    Location
    Derby
    MS-Off Ver
    Office 2013 - For my sins
    Posts
    122

    Re: VBA - Copy and paste only the cells with values

    Adding updated spreadsheet
    Attached Files Attached Files

  5. #5
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,870

    Re: VBA - Copy and paste only the cells with values

    I am still unsure about your request. Do you wish to copy from "Delete Zeros" Range B2:C5 to "Aged Grid" Range B4:C7. Apologize if I am not getting it but your instructions are not crystal clear. As I indicated earlier, specifics are the key to an answer.

  6. #6
    Forum Contributor
    Join Date
    04-09-2014
    Location
    Derby
    MS-Off Ver
    Office 2013 - For my sins
    Posts
    122

    Re: VBA - Copy and paste only the cells with values

    Quote Originally Posted by alansidman View Post
    I am still unsure about your request. Do you wish to copy from "Delete Zeros" Range B2:C5 to "Aged Grid" Range B4:C7. Apologize if I am not getting it but your instructions are not crystal clear. As I indicated earlier, specifics are the key to an answer.
    Thanks again for replying.

    Apologies if i'm not quite getting it across to you.

    So from "Delete Zeros" the range will always start with B2 but the list could be longer or shorter. This is where I need the macro to pick up only the cells with values. Then it will paste into "Aged Grid" always going to B4, that part is easy,

    It's getting the macro to pick up only the data that shows in Delete Zeros from B2.

    It will only be in columns B and C but rows can be from 1 to 12.

    Hope that clears things up. Please ask for anything else. Thanks again

  7. #7
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,870

    Re: VBA - Copy and paste only the cells with values

    Based upon your explanation and my understanding, this should be what you are looking for:
    Please Login or Register  to view this content.

  8. #8
    Forum Contributor
    Join Date
    04-09-2014
    Location
    Derby
    MS-Off Ver
    Office 2013 - For my sins
    Posts
    122

    Re: VBA - Copy and paste only the cells with values

    Quote Originally Posted by alansidman View Post
    Based upon your explanation and my understanding, this should be what you are looking for:
    Please Login or Register  to view this content.
    Thanks for helping but it keeps coming back with Run time error '1004' "We cant do that to a merged cell"

    The merged cells I have were originally in column B but now I've taken that out it still doesn't work.

    Not sure if you can help further? Thanks in advance.

  9. #9
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,870

    Re: VBA - Copy and paste only the cells with values

    When you get the error, what line of code is highlighted. Click on debug.
    The merged cells I have were originally in column B but now I've taken that out it still doesn't work.
    What does this mean. What happens? Does not work does not help me to help you. There were no merged cells in your example that conflicted with the code. Is your example not representative of the actual worksheet?

    Merged cells and VBA do not like each other. Most VBA developers avoid merged cells like the plague.

  10. #10
    Forum Contributor
    Join Date
    04-09-2014
    Location
    Derby
    MS-Off Ver
    Office 2013 - For my sins
    Posts
    122

    Re: VBA - Copy and paste only the cells with values

    Quote Originally Posted by alansidman View Post
    When you get the error, what line of code is highlighted. Click on debug.
    What does this mean. What happens? Does not work does not help me to help you. There were no merged cells in your example that conflicted with the code. Is your example not representative of the actual worksheet?

    Merged cells and VBA do not like each other. Most VBA developers avoid merged cells like the plague.
    I tried again on a clean sheet with your clean code and the merged cell error didn't show.

    When running, the dates copy across perfectly, in the correct place but the values do not go across.

    It should look like:

    April 1
    July 2
    August 26
    September 13

    All i'm getting is:

    April
    July
    August
    September

  11. #11
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,870

    Re: VBA - Copy and paste only the cells with values

    That is because, I was unsure what you wanted and guessed and only did a copy/paste on the first column. I am not a very good mind reader.

    Change the code to the following to include the second column.

    Please Login or Register  to view this content.

  12. #12
    Forum Contributor
    Join Date
    04-09-2014
    Location
    Derby
    MS-Off Ver
    Office 2013 - For my sins
    Posts
    122

    Re: VBA - Copy and paste only the cells with values

    I've tried it on it's own and it's absolutely perfect!! So thanks so much for that.

    The only problem now is when it's called from my other macro, nothing appears in column B or column C in "Aged Grid"

    No errors, and the message box you created appears as well I guess my other code affects yours? I've popped it below

    Please Login or Register  to view this content.

  13. #13
    Forum Moderator alansidman's Avatar
    Join Date
    02-02-2010
    Location
    Steamboat Springs, CO
    MS-Off Ver
    MS Office 365 Version 2404 Win 11 Home 64 Bit
    Posts
    23,870

    Re: VBA - Copy and paste only the cells with values

    What happens when you step through the code. Open your code in VBE. Click on Debug. Step through the code line by line (F8) and see what is happening to the highlighted line when you put your cursor on each line as it steps through. This will tell you exactly what is happening. I cannot see any issues.

  14. #14
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: VBA - Copy and paste only the cells with values

    Try this :
    Please Login or Register  to view this content.

  15. #15
    Forum Contributor
    Join Date
    04-09-2014
    Location
    Derby
    MS-Off Ver
    Office 2013 - For my sins
    Posts
    122

    Re: VBA - Copy and paste only the cells with values

    Quote Originally Posted by alansidman View Post
    What happens when you step through the code. Open your code in VBE. Click on Debug. Step through the code line by line (F8) and see what is happening to the highlighted line when you put your cursor on each line as it steps through. This will tell you exactly what is happening. I cannot see any issues.
    Thanks for replying again, i've tried to follow that and I too have not seen any errors.

    When putting my cursor on the lines should anything pop up other than things like =4165

    I followed all the lines and none of them skipped except the two below

    Please Login or Register  to view this content.
    Please Login or Register  to view this content.

  16. #16
    Forum Contributor
    Join Date
    04-09-2014
    Location
    Derby
    MS-Off Ver
    Office 2013 - For my sins
    Posts
    122

    Re: VBA - Copy and paste only the cells with values

    Quote Originally Posted by sanram View Post
    Try this :
    Please Login or Register  to view this content.
    Thanks for replying!

    I tried this and nothing happened. Nothing was deleted, nothing was pasted.

    I then put a msgbox to check if it completed and it did.

  17. #17
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: VBA - Copy and paste only the cells with values

    Quote Originally Posted by Frankinstyyn View Post
    Thanks for replying!

    I tried this and nothing happened. Nothing was deleted, nothing was pasted.

    I then put a msgbox to check if it completed and it did.
    This code is copying only from DeletedZero to Aged Grid. Do you want the code to copy Aged Grid to DeletedZeros without 0 values also?
    Last edited by sanram; 09-11-2016 at 08:40 PM.

  18. #18
    Valued Forum Contributor
    Join Date
    06-21-2013
    Location
    Bangladesh
    MS-Off Ver
    Excel 2000, Excel XP, Excel 2002, Excel 2007, Excel 2010, Excel 2013
    Posts
    975

    Re: VBA - Copy and paste only the cells with values

    Try this:
    Please Login or Register  to view this content.
    It will copying data without 0, then placing it to Aged Grid.

+ 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] Copy down and paste cell values from another cells
    By Rocky2013 in forum Excel Programming / VBA / Macros
    Replies: 6
    Last Post: 08-16-2013, 06:53 AM
  2. Replies: 8
    Last Post: 07-08-2013, 06:03 AM
  3. Formula to copy and paste data in cells to other cells based on values
    By haleakala17 in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 08-11-2012, 08:45 AM
  4. Copy/Paste Values in different cells!
    By Cyber-Fix in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 08-17-2011, 12:12 PM
  5. copy and paste without overwriting cells containing values
    By schueyisking in forum Excel General
    Replies: 1
    Last Post: 08-14-2008, 12:26 AM
  6. [SOLVED] Copy/Paste how to avoid the copy of formula cells w/o calc values
    By Dennis in forum Excel General
    Replies: 10
    Last Post: 03-02-2006, 06:50 PM
  7. Copy & Paste Unique Cells Values
    By Michael168 in forum Excel Programming / VBA / Macros
    Replies: 3
    Last Post: 06-01-2005, 07:14 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