如何将二维数组处理成where条件_如何用值填充二维数组,然后将结果放入范围...

Here is the question: "Suppose your program fills a large two-dimensional array called results with values, and you would like it to dump these values into an Excel range. For example, if results is m by n, you would like the program to dump the values into a range with m rows and n columns. One way is to use two nested loops to dump the data one element at a time into the appropriate cell."

What I've got so far:

Dim MyArray(m, n) As Long

Dim X as Long

Dim Y as Long

For X = 1 To m

For Y = 1 To n

MyArray(X, Y) = Cells(X, Y).Value

Next Y

Next X

I really need some help figuring this out I'm totally lost

解决方案

This fills the array with m rows and n columns and then transfers it all into a range starting in cell A1 of the ActiveSheet:

Sub FillRangeFromArray()

Dim m As Long

Dim n As Long

Dim x As Long

Dim y As Long

Dim MyArray() As String

'set the row and column dimensions

m = 100

n = 5

'redimension the array now that you have m and n

ReDim MyArray(1 To m, 1 To n)

'whenever possible lbound and ubound (first to last element)

'to loop through arrays, where

'MyArray,1 is the first (row) element and MyArray,2

'is the second (column) element

For x = LBound(MyArray, 1) To UBound(MyArray, 1)

For y = LBound(MyArray, 2) To UBound(MyArray, 2)

MyArray(x, y) = x & "-" & y

Next y

Next x

'fill the range in one fell swoop

'Resize creates a range resized to

'm rows and n columns

ActiveSheet.Range("A1").Resize(m, n).Value = MyArray

End Sub

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值