English 中文(简体)
将2-d 变式数据输入宇宙射线
原标题:Pushing 2-d Variant data into FormulaArray

I originally had a VBA function that returned a two dimensional variant array:

Public Function SplitIntoCells(some_data As String) As Variant()
End Function

我使用了阵列的辛奈,将其从另一 v功能中称作:

Public Function MyWrapper() as Variant
    MyWrapper = SplitIntoCells("somestring")
End Function

From Excel, if I select a big enough range and then do:

=MyWrapper()

随后是CTRL+SHIFT+ENTER,该数据明显分为每一组。

然而,为了实现自动化,如果我改变我的手法,则:

Public Function MyWrapper()
    ActiveSheet.Range("A1:E20").Select
    Selection.FormulaArray = SplitIntoCells("somestring")
End Function

以上只是工作。 在Excel,我看不到任何东西。

我做了什么错误?

最新情况:

就测试而言,如果我稍微修改MyWrapper()如下:

Public Function MyWrapper()
    Dim variant_temp() as Variant
    variant_temp = SplitIntoCells("somestring")
    ActiveSheet.Range("A1:E20").Select
    Selection.FormulaArray = variant_temp
End Function

variant_temp predictably has the 2-d array after returning from SplitIntoCells but the subsequent Selection.FormulaArray still has nothing in it even after the assignment. I am sure I am missing something blindingly obvious.

问题回答

A VBA user-defined function cannot modify the cell or range it s being called from: it can only return a value.





相关问题
import of excel in SQL imports NULL lines

I have a stored procedure that imports differently formatted workbooks into a database table, does work on them then drops the table. Here is the populating query. SELECT IDENTITY(INT,1,1) AS ID ...

Connecting to Oracle 10g with ODBC from Excel VBA

The following code works. the connection opens fine but recordset.recordCount always returns -1 when there is data in the table. ANd If I try to call any methods/properties on recordset it crashes ...

Excel date to Unix timestamp

Does anyone know how to convert an Excel date to a correct Unix timestamp?

C# GemBox Excel Import Error

I am trying to import an excel file into a data table using GemBox and I keep getting this error: Invalid data value when extracting to DataTable at SourceRowIndex: 1, and SourceColumnIndex: 1. As ...

Importing from excel "applications" using SSIS

I am looking for any tips or resources on importing from excel into a SQL database, but specifically when the information is NOT in column and row format. I am currently doing some pre-development ...

热门标签