Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Error when attempting to ignore omitted cells error

Posted on 2014-09-12
4
330 Views
Last Modified: 2014-09-13
I'm working on some code to export data from Access to Excel (via Access VBA) and then add some formulas to the worksheet.  The export process is working great.  

I then insert a formula over a range and format the numbers in that range, this also works great.  

However, since my formula is in the cell 2 columns over from the last of the columns that is being summed, I'm getting the green warning triangle with the omitted cells warning.  My current code is shown below.  However the rng.Errors line raises an error:

1004 Application-defined or object-defined error

and then kicks me out of excel.  Strangely, this also sets the visible property of the Excel object to False so I cannot see it in the quick launch bar, but it is visible in Task Manager.

Anybody have any ideas why this syntax is not working?
Public Sub Sum_Rows_and_Columns(StartCol As Integer)

    Dim lngRowCount As Long
    Dim lngColCount As Long
    Dim strFormula As String
   
    On Error GoTo ProcError
    
    Set xl = GetObject(, "Excel.application")
    Set wbk = xl.activeworkbook
    Set sht = wbk.activesheet
    
    lngRowCount = sht.usedrange.rows.Count
    lngColCount = sht.usedrange.columns.Count
    
    Set rng = sht.Range(sht.cells(2, lngColCount + 2), sht.cells(lngRowCount, lngColCount + 2))
    strFormula = "=Sum(RC[" & StartCol - (lngColCount + 2) & "]:RC[-2]"
    rng.Formula = strFormula
    rng.NumberFormat = "#,###.00"
    rng.Errors(5).Ignore = True     '5=xlOmittedCells

    sht.columns(lngColCount + 2).Entirecolumn.autofit
    
ProcExit:
    On Error Resume Next
    Set sht = Nothing
    Set wbk = Nothing
    Set xl = Nothing
    Exit Sub
    
ProcError:
    MsgBox "Sum_Rows_And_Columns" & vbCrLf & Err.Number & vbCrLf & Err.Description
    Debug.Print "Sum_Rows_And_Columns", Err.Number, Err.Description
    Resume ProcExit
    
End Sub

Open in new window

0
Comment
Question by:Dale Fye (Access MVP)
  • 2
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
Glenn Ray earned 500 total points
ID: 40320382
I think you can turn off that error checking for the entire Excel instance by adding this command after your wbk and sht assignments:
xl.ErrorCheckingOptions.OmittedCells = False

Then remove the command at line 20 in your code (rng.Errors(5).Ignore = True)

Regards,
-Glenn

PS  I ran this Access VBA code on a dummy Excel workbook and never did see the "Omit Adjacent Cells" error flag appear even though it was turned on. Wierd.
0
 
LVL 47

Author Closing Comment

by:Dale Fye (Access MVP)
ID: 40321024
Glenn,

Worked like a charm.

Any idea why the other method did not work?  Based on the help file, I would have thought that method would work just fine.

Any chance you already have those warnings turned off in the Excel file you tested it on?
0
 
LVL 27

Expert Comment

by:Glenn Ray
ID: 40321069
Dale,

Maybe I didn't set up a data table close enough to your example, but when I turn all the error flagging ON, the only time I saw the error was when omitting cells in a vertical (column-based) function (like SUM).  When I was adding across columns, I didn't see the error.

Admittedly, I've never used the Errors(x).Ignore method in VBA, so I can't say what, if anything, is an issue with that statement.  (Microsoft reference: http://msdn.microsoft.com/en-us/library/office/ff195953(v=office.14).aspx)

-Glenn
0
 
LVL 47

Author Comment

by:Dale Fye (Access MVP)
ID: 40321079
I was getting the warning flags when i summed columns (not in the example)  and rows,
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.
This Micro Tutorial will demonstrate the scrolling table in Microsoft Excel using the INDEX function.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question