+ Reply to Thread
Results 1 to 10 of 10

VBA to Clear Cells that Contain #N/A and also VBA to re populate formula in #N/A cells

  1. #1
    Registered User
    Join Date
    07-02-2016
    Location
    Vernon BC
    MS-Off Ver
    2013
    Posts
    17

    VBA to Clear Cells that Contain #N/A and also VBA to re populate formula in #N/A cells

    So Im trying to Plot some lines with gaps in 2013 excel with 3 rows containing thousands of cells

    In order to plot the gaps I have to remove the formula in the #N/A cells

    But if possible I still need to re populate the formula back to the cells ?

    Work Sheet name is " Curve Data "


    The attached file has a sample of data I would like to plot ( work restrictions on formulas )

    Thanks in Advance, Gerry
    Attached Files Attached Files

  2. #2
    Valued Forum Contributor
    Join Date
    01-08-2011
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2007 to 2016
    Posts
    456

    Re: VBA to Clear Cells that Contain #N/A and also VBA to re populate formula in #N/A cell

    Rather than remove the formula, could you just change it so that it doesn't return #N/A values?

    If you put IFERROR([your formula],"")

    this will return blank instead of #N/A value.
    Excel is a constant learning process and it's great to help each other. If any of us have helped you today, a click on the "reputation" star on the left is appreciated.

  3. #3
    Forum Expert mikerickson's Avatar
    Join Date
    03-30-2007
    Location
    Davis CA
    MS-Off Ver
    Excel 2011
    Posts
    6,229

    Re: VBA to Clear Cells that Contain #N/A and also VBA to re populate formula in #N/A cell

    The workbook that you attached contains no formulas and there is no sheet named " Curve Data "

    If you have formulas that return troublesome #NA values, have you tried replacing them with
    =IFERROR(ExistingFormula, 0)
    _
    ...How to Cross-post politely...
    ..Wrap code by selecting the code and clicking the # or read this. Thank you.

  4. #4
    Registered User
    Join Date
    07-02-2016
    Location
    Vernon BC
    MS-Off Ver
    2013
    Posts
    17

    Re: VBA to Clear Cells that Contain #N/A and also VBA to re populate formula in #N/A cell

    The Issue Im having is that If excel sees a formula in a cell it is not truly blank... and therefor will not plot line gaps on the Line Chart ?

    there will still be a line from last good value to first new value even when "" is used.

  5. #5
    Valued Forum Contributor
    Join Date
    01-08-2011
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2007 to 2016
    Posts
    456

    Re: VBA to Clear Cells that Contain #N/A and also VBA to re populate formula in #N/A cell

    Hi Gerry,

    I did a bit of research and found something on stackoverflow which might work. If you set the IFERROR formula as:

    =IFERROR([your formula],#N/A)

    then set your chart to show hidden or empty cells as gaps, this seems to ignore the #N/A values completely.

    I tried it on a small sample of data I created and it seems to work

  6. #6
    Registered User
    Join Date
    07-02-2016
    Location
    Vernon BC
    MS-Off Ver
    2013
    Posts
    17

    Re: VBA to Clear Cells that Contain #N/A and also VBA to re populate formula in #N/A cell

    The formula Im using is =IF(AND(G5>=$CC$1,G5<=$CD$1),$CB$1,$CA$1) $CA$1 refers to #N/A in that cell
    even if I put #N/A instead of $CA$1 it wont work for me to show data in hidden columns ?

    Unless I modify the formula to IFERROR but Im not sure how ?

    Thanks in advance, Gerry.

  7. #7
    Valued Forum Contributor
    Join Date
    01-08-2011
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2007 to 2016
    Posts
    456

    Re: VBA to Clear Cells that Contain #N/A and also VBA to re populate formula in #N/A cell

    If I'm understanding you correctly, CA1 would either be a number or #N/A if some kind of lookup(?) fails?

    I tried a very simple version of what you have (see attached) and the #N/A is always ignored on the charts. I even tried just typing #N/A into one of the lookup cells to see if that made a difference, but the chart still plots correctly, just ignoring the #N/A values.

    However, if you are getting an error you could try:

    =IFERROR(IF(AND(G5>=$CC$1,G5<=$CD$1),$CB$1,$CA$1),#N/A)
    Attached Files Attached Files

  8. #8
    Registered User
    Join Date
    07-02-2016
    Location
    Vernon BC
    MS-Off Ver
    2013
    Posts
    17

    Re: VBA to Clear Cells that Contain #N/A and also VBA to re populate formula in #N/A cell

    This is what I see no breaks in lines maybe not working for some reason here.


    Capture22.JPG

  9. #9
    Registered User
    Join Date
    07-02-2016
    Location
    Vernon BC
    MS-Off Ver
    2013
    Posts
    17

    Re: VBA to Clear Cells that Contain #N/A and also VBA to re populate formula in #N/A cell

    Here is a Sample Shirley of Before and After with the VBA ( Clear Cell N/A )

    before sample.JPG

    after sample.JPG

  10. #10
    Valued Forum Contributor
    Join Date
    01-08-2011
    Location
    Portsmouth, England
    MS-Off Ver
    Excel 2007 to 2016
    Posts
    456

    Re: VBA to Clear Cells that Contain #N/A and also VBA to re populate formula in #N/A cell

    Ah, sorry, the penny just dropped!

    You want something like this:

    Chart Pic.png

    I found this article where someone had managed to do it with a "mask". Can't say I've tried it but might be worth a go.

    http://www.andypope.info/charts/brokenlines.htm

    If not, we're back to the VBA route which is doable, but you might want to create a separate column for your chart data to save removing the formulas then having to put them back in. I'll have a look at creating some code for you.

+ 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: 13
    Last Post: 06-15-2016, 03:37 PM
  2. Clear cells, Copy formula and paste, populate formulas by combining macros
    By Sekars in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 04-27-2016, 02:14 AM
  3. Replies: 5
    Last Post: 10-15-2012, 06:33 PM
  4. Clear contents of cells that do not contain specific text, sort cells that do
    By feckless.lout in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-27-2010, 01:41 AM
  5. week end formula & clear cells button
    By bassett in forum Excel Programming / VBA / Macros
    Replies: 5
    Last Post: 12-26-2009, 11:56 PM
  6. Look Through Sheet & Clear Cells which do not have formula
    By pr4t3ek in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-14-2009, 12:14 AM
  7. Formula to clear cells based on another cell value
    By mrdata in forum Excel General
    Replies: 2
    Last Post: 02-22-2008, 05:58 AM

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