+ Reply to Thread
Results 1 to 20 of 20

Copy data range but ignore (not copy) cells with formula

  1. #1
    Registered User
    Join Date
    03-23-2019
    Location
    Illinois
    MS-Off Ver
    2007 / 2016
    Posts
    19

    Copy data range but ignore (not copy) cells with formula

    I have a budgeting worksheet that contains multiple sheets and formulas. A user can enter his data into the ledger, and various financial scenarios are automatically calculated. The ledger contains some cells that contain formulas, and may be over-written by the user. That is fine since the worksheet is projecting month per month, and must be updated with actual entries to keep the projections accurate.

    Occasionally I update/upgrade the budgeting worksheet, and want the user to be able to export his data from the old worksheet and import it to the new worksheet. I have created a macro that exports the data for certain ranges. I have also created a macro that imports the data range to the new worksheet.

    However, my problem is that the macro to export also converts predetermined calculations from their original formula (=A1+B2, for example) to whatever the result is for that formula ($1,200, for example). This causes problems for future projections in other data ranges since the formula is now replaced with a static number that cannot change based upon other monthly deposits/withdrawals.

    I have tried exporting the data minus any cells that contain formulas but have been unsuccessful. I have attached my working export code (as I have many sheets and ranges, I have only posted the minimum to show what I have working). I have also attached the code I used for ignoring cells with formulas (inspired by this post Excel VBA Copy / Paste macro: Ignore cells with Formulas). Any help is greatly appreciated. As is surely obvious, I am new to VBA and know next to nothing about it!

    WORKING EXPORT CODE:
    Please Login or Register  to view this content.
    NON-WORKING: IGNORE CELLS WITH FORMULA
    Please Login or Register  to view this content.
    Moderator's note: Please take the time to review our rules. There aren't many, and they are all important. Rule #2 requires code tags. I have added them for you this time because you are a new member. --6StringJazzer
    Last edited by 6StringJazzer; 03-23-2019 at 10:33 AM.

  2. #2
    Forum Expert KOKOSEK's Avatar
    Join Date
    08-03-2018
    Location
    Pole in Yorkshire, UK
    MS-Off Ver
    365/2013
    Posts
    2,743

    Re: Copy data range but ignore (not copy) cells with formula

    Please Login or Register  to view this content.
    Happy with my answer * Add Reputation.
    If You are happy with solution, please use Thread tools and mark thread as SOLVED.

  3. #3
    Registered User
    Join Date
    03-23-2019
    Location
    Illinois
    MS-Off Ver
    2007 / 2016
    Posts
    19

    Re: Copy data range but ignore (not copy) cells with formula

    6StringJazzer - Sorry, and thank you!
    Last edited by mattman1968; 03-23-2019 at 03:04 PM.

  4. #4
    Registered User
    Join Date
    03-23-2019
    Location
    Illinois
    MS-Off Ver
    2007 / 2016
    Posts
    19

    Re: Copy data range but ignore (not copy) cells with formula

    Kokosek - Appreciate the quick response. Do I just add that to my working code?

  5. #5
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Copy data range but ignore (not copy) cells with formula

    The problem seems to be that the Source and Range are the same. You are copying values right back to where they came from. Here is your code with commentary. I am assuming this code is in a standard module (like Module1) and not a worksheet module (like Sheet1).
    Please Login or Register  to view this content.
    Jeff
    | | |會 |會 |會 |會 | |:| | |會 |會
    Read the rules
    Use code tags to [code]enclose your code![/code]

  6. #6
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Copy data range but ignore (not copy) cells with formula

    How about
    Please Login or Register  to view this content.

  7. #7
    Registered User
    Join Date
    03-23-2019
    Location
    Illinois
    MS-Off Ver
    2007 / 2016
    Posts
    19

    Re: Copy data range but ignore (not copy) cells with formula

    Thank you everyone for your suggestions. I will try them when I get more time and report back in a couple days.

  8. #8
    Registered User
    Join Date
    03-23-2019
    Location
    Illinois
    MS-Off Ver
    2007 / 2016
    Posts
    19

    Re: Copy data range but ignore (not copy) cells with formula

    I have tried several suggestions from this site, as well others, but since I am not really sure how to write code in the first place, I am getting nowhere. For the record, the code I posted as "working" I tweaked from an online source and it does exactly what I want...except it copies cells with formulas. The "working" code creates a new workbook with the same tabs, and exports the data to the same respective cells. Now if only I can edit my existing "working" code to eliminate the copying of cells with formulas? For reference here is the full "working" code minus all the sheets/data ranges.

    Thanks!

    Please Login or Register  to view this content.
    Last edited by mattman1968; 03-25-2019 at 11:40 AM.

  9. #9
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Copy data range but ignore (not copy) cells with formula

    I think we need to start over again with understanding what you want, because you've gotten two or three solutions here. I suppose part of the problem is that you're new to VBA.

    What do you want to do for the cells that contain formulas? You said "ignore" but do you just want to leave those blank in your destination?

    If you want to leave them blank, we can adapt one of the solutions given and package it up with the code you provided.

  10. #10
    Registered User
    Join Date
    03-23-2019
    Location
    Illinois
    MS-Off Ver
    2007 / 2016
    Posts
    19

    Re: Copy data range but ignore (not copy) cells with formula

    Quote Originally Posted by 6StringJazzer View Post
    What do you want to do for the cells that contain formulas? You said "ignore" but do you just want to leave those blank in your destination?
    Yes. I want to leave cells with formulas blank in the destination. I apologize if I worded incorrectly before.

  11. #11
    Forum Guru
    Join Date
    09-10-2017
    Location
    Chippenham, England
    MS-Off Ver
    365
    Posts
    15,080

    Re: Copy data range but ignore (not copy) cells with formula

    Does this work for the first range in the HELOC sheet?
    Please Login or Register  to view this content.

  12. #12
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Copy data range but ignore (not copy) cells with formula

    This is a complete replacement for the code you've provided, so hopefully it will be easy for you to put it in your file. I took the code from your first post that works, modified it based on your approach to use a Sub to do the copy, and used KOKOSEK's method for detecting a formula (although your original method was also valid). Your problem was in how you were calling copy_non_formulas, as I described in my first post.

    I compiled this but cannot run it without having your file and it would be too time-consuming for me to create one based on guessing what it looks like. If this still does not work then I suggest attaching your file with any sensitive data removed or faked.

    Please Login or Register  to view this content.

  13. #13
    Registered User
    Join Date
    03-23-2019
    Location
    Illinois
    MS-Off Ver
    2007 / 2016
    Posts
    19

    Re: Copy data range but ignore (not copy) cells with formula

    I appreciate the code 6stringjazzer. Unfortunately, it results in an error: Object Required. No other info is provided. I tried tweaking it a bit but got nothing. If this is an easy fix for someone, I appreciate the time and effort. I'm ready to give up though. I will try to provide a dumbed-down version of my workbook but that may not happen for a while either...real work to do

    Thanks again, all!

  14. #14
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Copy data range but ignore (not copy) cells with formula

    When you get the error, click Debug. What line of code is highlighted when the error occurs? That error is usually easy to fix, but we need to know what object is causing it.

  15. #15
    Registered User
    Join Date
    03-23-2019
    Location
    Illinois
    MS-Off Ver
    2007 / 2016
    Posts
    19

    Re: Copy data range but ignore (not copy) cells with formula

    When the error pops up, I am not allowed to click anything else. I have to close out the dialog box, then when I select debug, nothing happens with any of the options unless I choose Debug>Run to cursor. Below are the only lines that become highlighted...but only when I place the cursor right after said line and select Debug>Run to cursor. Every other line gives a Run time error 424. Sorry if this is not helpful.

    Please Login or Register  to view this content.

  16. #16
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Copy data range but ignore (not copy) cells with formula

    What is ActiveSheet at the time this code is executed?

    I am confused by your description of what happens when an error occurs. This is what you should expect to see:
    errordialog.JPG

    and if you press debug you should see a line of code highlighted like this:
    errorhighlight.JPG

  17. #17
    Registered User
    Join Date
    03-23-2019
    Location
    Illinois
    MS-Off Ver
    2007 / 2016
    Posts
    19

    Re: Copy data range but ignore (not copy) cells with formula

    I have seen the errors highlighted like you describe...but not in this instance. The error dialog box comes up and I am not allowed to press debug unless I close the error box.VBA.png

  18. #18
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Copy data range but ignore (not copy) cells with formula

    I had an error, remove the .Value as shown in red.

    I also added something that should help it run faster, see additional red code below.
    Please Login or Register  to view this content.

  19. #19
    Registered User
    Join Date
    03-23-2019
    Location
    Illinois
    MS-Off Ver
    2007 / 2016
    Posts
    19

    Re: Copy data range but ignore (not copy) cells with formula

    Quote Originally Posted by 6StringJazzer View Post
    I had an error, remove the .Value as shown in red.

    I also added something that should help it run faster, see additional red code below.
    THANK YOU SO MUCH!!! It appears to be working as desired. I will have to test on a larger scale but I think it's good to go. I truly appreciate this!

  20. #20
    Administrator 6StringJazzer's Avatar
    Join Date
    01-27-2010
    Location
    Tysons Corner, VA, USA
    MS-Off Ver
    MS365 Family 64-bit
    Posts
    24,721

    Re: Copy data range but ignore (not copy) cells with formula

    Phew! Glad it helped!

    If your question has been answered please mark your thread as "Solved" so that members will know by looking at the thread title that your problem is solved. Go to the menu immediately above your first post to the thread and click on Thread Tools. From the dropdown menu select "Mark this thread as solved..."

    If a member helped you solve your problem, consider adding to their reputation by clicking on the star icon addreputationiconsmall.jpg below their name.

+ 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] How to copy rows that are complete with data and ignore blank/error cells
    By Beh162 in forum Excel Formulas & Functions
    Replies: 8
    Last Post: 02-11-2019, 10:05 AM
  2. Copy Range and Paste only Values (ignore blank cells)
    By ksayet in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 11-18-2015, 04:37 PM
  3. [SOLVED] Formula to ignore blank cells and copy data that meets criteria?
    By Office_Dummy in forum Excel Formulas & Functions
    Replies: 2
    Last Post: 04-27-2014, 12:29 PM
  4. [SOLVED] Copy data from a range of cells into a blank range based on common cell
    By vanmeterkj in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-03-2012, 10:18 AM
  5. [SOLVED] VBA Copy a range of cells values using the range of cells in a formula (which will change)
    By murtaep in forum Excel Programming / VBA / Macros
    Replies: 32
    Last Post: 06-05-2012, 07:59 AM
  6. Replies: 2
    Last Post: 05-31-2012, 05:37 AM
  7. Copy range of cell data to range of cells arranged by groups
    By Wayne Makeeff in forum Excel General
    Replies: 0
    Last Post: 01-27-2005, 12:17 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