The VBA function calls the VBA submenu to print the array to the worksheet.

I currently have a custom function that runs several routines related to matrix generation. To correctly check these matrices, I want to place them on a sheet. A user-defined function works fine, and I added it below in the place where I want to find out what is in the array:

Call CheckArray(TestArray)

Where the "TestArray" in the above variant varies depending on the array I want to look at.

The routine "CheckArray" is as follows:

Sub CheckArray(MyArray As Variant)
MatrixRows = UBound(MyArray, 1)
MatrixCols = UBound(MyArray, 2)

MsgBox MyArray(11, 2)
MsgBox "Matrix size = " & MatrixRows & " rows x " & MatrixCols & " columns"

ActiveWorkbook.Worksheets("Check array").[A1].Resize(MatrixRows, MatrixCols) = MyArray
End Sub

, MsgBox , , sub , . , , , , , , , - , .

, , . - , ?

, ? ?

+4
1

:

, , , . , Immediate.

MS Excel 2010 Immediate VBA (Alt + F11), "" - " " (Ctrl + G).

Immediate, , :

Call WriteArrayToImmediateWindow(MyArray)

"MyArray" - , .

'WriteArrayToImmediateWindow', :

Sub WriteArrayToImmediateWindow(arrSubA As Variant)

Dim rowString As String
Dim iSubA As Long
Dim jSubA As Long

rowString = ""

Debug.Print
Debug.Print "The array is: "
For iSubA = 1 To UBound(arrSubA, 1)
    rowString = arrSubA(iSubA, 1)
    For jSubA = 2 To UBound(arrSubA, 2)
        rowString = rowString & "," & arrSubA(iSubA, jSubA)
    Next jSubA
    Debug.Print rowString
Next iSubA

End Sub

User3706920: Immediate VBA?

EDIT:

, Immediate , , Excel. , :

, , :

Call WriteToFile(MyArray)

"MyArray" , . WriteToFile :

Sub WriteToFile(arrSubA As Variant)
'To export array to a text file
    'Setup
    Dim FSO As Object
    Dim ofs As Object
    Dim Output As Variant
    Dim rowString As String
    Dim iSubA As Long
    Dim jSubA As Long
    rowString = ""

    'Create file
    Set FSO = CreateObject("Scripting.FileSystemObject")
    Dim oFile As Object
    Set oFile = FSO.CreateTextFile("C:\Users\" & Environ$("username") & "\Desktop\Array.txt")
    oFile.Close
    For iSubA = 1 To UBound(arrSubA, 1)
        rowString = arrSubA(iSubA, 1)
        For jSubA = 2 To UBound(arrSubA, 2)
            rowString = rowString & "," & arrSubA(iSubA, jSubA)
        Next jSubA
        If Len(Dir("C:\Users\" & Environ$("username") & "\Desktop\Array.txt")) > 0 Then
            Set ofs = FSO.OpenTextFile("C:\Users\" & Environ$("username") & "\Desktop\Array.txt", 8, True)
        End If
        ofs.WriteLine rowString
        ofs.Close
    Next iSubA
End Sub

Excel - , :

Sub OpenArrayFile()
'To open array text file in Excel
    Workbooks.OpenText Filename:="C:\Users\" & Environ$("username") & "\Desktop\Array.txt", Origin:= _
        xlMSDOS, StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote _
        , ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, Comma:=True _
        , Space:=False, Other:=False, FieldInfo:=Array(1, 1), _
        TrailingMinusNumbers:=True
End Sub

, !

+1

All Articles