开发者

Referencing .Cells (row, 0) generates error 1004

I get an error 1004 at the line: ActiveSheet.Cells(row, 0).Text = elements(i).

Sub Mogelijkheden()
Workbooks("Model-v6-final-test_macro_2.xlsm").Sheets("Variaties").Activate
ActiveSheet.Activate

Dim elements(3) As Variant
elements(0) = ActiveSheet.Cells(3, 2).Text
elements(1) = ActiveSheet.Cells(4, 2).Text
elements(2) = ActiveSheet.Cells(5, 2).Text

Dim length As Integer
length = UBound(elements) - LBound(开发者_运维问答elements) + 1

Dim i As Integer
Dim j As Integer
Dim k As Integer
Dim x As Integer
Dim y As Integer
Dim z As Integer
Dim c As Integer
Dim b As Integer
Dim v As Integer
Dim n As Integer

Dim row As Integer
row = 10

'Now, "print" the combinations by looping through your array
For i = 0 To length
For j = 0 To length
For k = 0 To length
For x = 0 To length
For y = 0 To length
For z = 0 To length
For c = 0 To length
For b = 0 To length
For v = 0 To length
For n = 0 To length

ActiveSheet.Cells(row, 0).Text = elements(i)
ActiveSheet.Cells(row, 1).Text = elements(j)
ActiveSheet.Cells(row, 2).Text = elements(k)
ActiveSheet.Cells(row, 3).Text = elements(x)
ActiveSheet.Cells(row, 4).Text = elements(y)
ActiveSheet.Cells(row, 5).Text = elements(z)
ActiveSheet.Cells(row, 6).Text = elements(c)
ActiveSheet.Cells(row, 7).Text = elements(b)
ActiveSheet.Cells(row, 8).Text = elements(v)
ActiveSheet.Cells(row, 9).Text = elements(n)

row = row + 1

Next n
Next v
Next b
Next c
Next z
Next y
Next x
Next k
Next j
Next i

End Sub


Change the length assignment to:

length = ubound(elements) - 1

Also, you want:

ActiveSheet.cells(row, 1).value = elements(i)

You can't write to the Text property


ActiveSheet.Cells(row, 0).Text = elements(i)

There is no column 0 in excel. You'll have to start with column 1 and go to 10.

.Text is also a read-only property of a range object. Use .Formula instead.

Once you fix those, you'll find your loops go too high (your Length = 4, but it should really be =3, and your loop should go just 0 to 2).

EDIT: Even once you fix those, you'll have more problems. I won't give them all away, but suffice it to say that 3^10 = 59,049, which could create problems with smaller numeric data types.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜