+ Reply to Thread
Results 1 to 1 of 1

unable to set FormulaArray property of Range class Error

Hybrid View

  1. #1
    Registered User
    Join Date
    11-23-2011
    Location
    FL
    MS-Off Ver
    Excel 2003
    Posts
    2

    unable to set FormulaArray property of Range class Error

    Hi all. I have been lurking for a while and have learned much from the excel forum. Thanks.

    More info here as well

    I have attached a sample database which uses the excel functions. If you want to look at the underlying data, hold down Shift Key while opening, as I have a form loading on start.

    I am getting the "unable to set FormulaArray property of Range class" error when doing the below code. When I place my breakpoint I can trace to this line:
    objResultsRange.FormulaArray = objExcel.Transpose(varResults).

    Sometimes this works with some ranges but does not work with others. Any help or insight would be greatly appreciated.


    strQuery = "SELECT [Detail].[Menu Item] AS ItemSold, Sum([Detail].[Quantity]) AS TotalQty, Sum([Detail].[Item Price]) AS TotalSale, "
        strQuery = strQuery & "[Detail].[Department Name] AS DeptName, [Detail].[Category Name] AS CategoryName "
        strQuery = strQuery & "FROM [Detail] "
        strQuery = strQuery & "WHERE (((CDate([Date])) >= #" & datStartDate & "# And (CDate([Date])) <= #" & datEndDate & "#)) "
        strQuery = strQuery & "GROUP BY [Detail].[Department Name], [Detail].[Category Name], [Detail].[Menu Item] "
        strQuery = strQuery & "ORDER BY [Detail].[Department Name], [Detail].[Category Name], [Detail].[Menu Item];"
        
        Set rstResults = CurrentDb.OpenRecordset(strQuery)
        varResults = rstResults.GetRows(2 ^ 15)
        rstResults.Close
        Set rstResults = Nothing
        
        Set objExcel = CreateObject("Excel.Application")
        objExcel.Workbooks.Add
        Set objResultsWorkbook = objExcel.Workbooks(objExcel.Workbooks.Count)
        Set objResultsSheet = objResultsWorkbook.Worksheets("Sheet1")
        Set objResultsRange = objResultsSheet.Range("A2:E" & 2 + UBound(varResults, 2))
        objResultsRange.FormulaArray = objExcel.Transpose(varResults)
        objResultsSheet.Range("A1").Value = "Item Sold"
        objResultsSheet.Range("B1").Value = "Total Qty"
        objResultsSheet.Range("C1").Value = "Total Sale"
        objResultsSheet.Range("D1").Value = "Department Name"
        objResultsSheet.Range("E1").Value = "Category Name"
        objResultsSheet.Range("A:E").Columns.AutoFit
        objExcel.Visible = True
        Set objResultsRange = Nothing
        Set objResultsSheet = Nothing
        Set objResultsWorkbook = Nothing
        Set objExcel = Nothing
    Attached Files Attached Files
    Last edited by BuglerX; 11-24-2011 at 01:10 AM. Reason: adding reference

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

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