+ Reply to Thread
Results 1 to 4 of 4

Change Excel error #N/A to 0 in set ranges, due to no data in database

Hybrid View

  1. #1
    Registered User
    Join Date
    03-23-2015
    Location
    Cecilia, LA
    MS-Off Ver
    2010
    Posts
    3

    Change Excel error #N/A to 0 in set ranges, due to no data in database

    Excel VBA code to change #N/A to 0 in set ranges does not work. Workbook has a sheet for each day to the month, a button on each that runs macro to get data from a database PI System, based on the date on the sheet. Formula's are set up to pull the data for each hour. Trouble is when there is no data, like when the time changes to DST there is no 24th hour, it inserts error #N/A. Other macro's insert this gathered data at other locations on the sheet, thus #N/A's are carried over. I want to change those #N/A's to 0. My code is supposed to change only those #N/A's, which is set ranges, to values first, then replace them with 0. I don't need to change the first location this data enters the sheet. I have tried different ways & it still doesn't work.

    Part of my latest ChangeErrors() Sub is:
    Range("C12:Z13").Copy
    Range("C12:Z13").PasteSpecial Paste:=xlPasteValues
    Range("C12:Z13").Replace What:="#N/A", Replacement:="0"

    I have searched the questions that others have asked and found nothing that might help. Please, any suggestions?

  2. #2
    Forum Expert
    Join Date
    10-09-2014
    Location
    Newcastle, England
    MS-Off Ver
    2003 & 2013
    Posts
    1,986

    Re: Change Excel error #N/A to 0 in set ranges, due to no data in database

    Wrap your cell formula in the following:

    If (ISERROR(your formula),0,your formula)
    If someone has helped you then please add to their Reputation

  3. #3
    Registered User
    Join Date
    03-23-2015
    Location
    Cecilia, LA
    MS-Off Ver
    2010
    Posts
    3

    Re: Change Excel error #N/A to 0 in set ranges, due to no data in database

    I removed my sub ChangeErrors() and tried changing the cell formula's.
    Cell BD34 has formula:
    {=PISampDat($CM$11,$AF$1,$AF$2,$AG$1,0,)}
    Cell BE34 has formula:
    {=PISampDat($CM$12,$AF$1,$AF$2,$AG$1,0,)}
    Cell BF34 has formula:
    {=PISampDat($CM$13,$AF$1,$AF$2,$AG$1,0,)}
    In cell BG34 I am able to change the function formula as you recommended to:
    =IF(ISERROR(BD34-(BE34+BF34)),0,(BD34-(BE34+BF34)))

    Some of the cells that have curly brackets { }, there is a macro that copies that data (24 rows, 1 for each hr., same formula for the 24 hrs.) and transposes to another location on the sheet.
    Cells AJ11:AJ34 have:
    {=PISampDat($AY$8,$AF$1,$AF$2,$AG$1,0,)}

    My Sub EnterMeteredData()
    Range("AJ11:AJ35").Copy
    Range("C12").PasteSpecial Paste:=xlValues, Transpose:=True

    When I tried to change function formula to:
    {=IF(ISERROR(PISampDat($AY$8,$AF$1,$AF$2,$AG$1,0,),0,(PISampDat($AY$8,$AF$1,$AF$2,$AG$1,0,))))}
    I get error: You've entered too many arguments for this function. When I click OK, the 0 between the comma's is highlighted.
    Any suggestion on what I need to do?

  4. #4
    Registered User
    Join Date
    03-23-2015
    Location
    Cecilia, LA
    MS-Off Ver
    2010
    Posts
    3

    Re: Change Excel error #N/A to 0 in set ranges, due to no data in database

    Found out I can't use this:
    =IF(ISERROR(BD34-(BE34+BF34)),0,(BD34-(BE34+BF34)))
    It has to be:
    =IF(ISERROR(BD34-(BE34+BF34))<0,0,(BD34-(BE34+BF34)))
    If the result is less than 0 it needs to show 0.
    I am going to try this, will post if it works.
    Nope, it doesn't. Still get #N/A when database doesn't have data (when time changes to DST, there is no 24th hr).
    The macro to Copy.PasteSpecial Paste=xlValues, Transpose:=True
    returns #N/A.

    Tried:
    =IF(ISNA(BD34-(BE34+BF34))<0,0,(BD34-(BE34+BF34)))
    Still get #N/A when database doesn't have data.

    I think I'm grasping at straws
    Last edited by DonnaTrahan; 03-31-2015 at 12:01 PM. Reason: If result is less than 0, need it to show 0

+ 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. change Access database to Excel database using VBA
    By zafirah in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 07-25-2013, 01:13 AM
  2. Error in Excel data to Access Database
    By Arnav in forum Excel General
    Replies: 0
    Last Post: 03-18-2010, 01:58 PM
  3. Excel query of Access database - changed database filename, now error
    By ucdcrush@gmail.com in forum Excel General
    Replies: 2
    Last Post: 03-08-2006, 04:45 PM
  4. [SOLVED] trying to import excel database into outlook need to name ranges
    By Shawnee Wright in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 09-06-2005, 02:05 AM
  5. Replies: 0
    Last Post: 03-15-2005, 03:06 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