昨天我问了你们一个非常模糊的问题。我现在已经设法隔离了这个问题,但显然没有解决我在这里写的问题。
我的问题是为变量分配矩阵的值/内容(或变体的变体)。不确定这是否是多余的,但我想在我的电子表格中包含以下内容:
A B C D E F
1 a b c d
2 e f g h
3 aa bb cc dd
4 ee ff gg hh
这是代码:
Public Sub Test()
Dim sub_data As Variant
Dim sheet_name As String
Dim str As String
Dim rng As Range
sheet_name = "Sheet1"
Set rng = Sheets(sheet_name).Range("A1")
Worksheets(sheet_name).Cells.ClearContents
On Error Resume Next
str = "A" & CStr(print_row)
ReDim sub_data(0 To 1, 0 To 1, 0 To 3)
sub_data(0, 0, 0) = "a"
sub_data(0, 0, 1) = "b"
sub_data(0, 0, 2) = "c"
sub_data(0, 0, 3) = "d"
sub_data(0, 1, 0) = "e"
sub_data(0, 1, 1) = "f"
sub_data(0, 1, 2) = "g"
sub_data(0, 1, 3) = "h"
sub_data(1, 0, 0) = "aa"
sub_data(1, 0, 1) = "bb"
sub_data(1, 0, 2) = "cc"
sub_data(1, 0, 3) = "dd"
sub_data(1, 1, 0) = "ee"
sub_data(1, 1, 1) = "ff"
sub_data(1, 1, 2) = "gg"
sub_data(1, 1, 3) = "hh"
Call PrintArray(sub_data, str)
End Sub
Public Sub PrintArray(Data As Variant, Cl As String)
Dim ubnd_1, ubnd_2 As Integer
Dim sub_data As Variant
ubnd_1 = UBound(Data, 2)
ubnd_2 = UBound(Data, 3)
sub_data = Data(0) 'THIS LINE WON'T WORK. HOW TO ASSIGN CORRECTLY?
'here I want to print the content of the Data-variable onto the sheet
Range(Cl).Resize(ubnd_2 + 1, ubnd_1 + 1) = Application.Transpose(sub_data)
End Sub