Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Become a Premium Member and unlock a new, free course in leading technologies each month.

Solved

Posted on 2011-09-24

c array size is x

b array size is x2

I have the following table for example.

c(1) = b(1)

c(2)=((b(2)+1)*(c(1)+1))-1

c(3)=)(b(3)+1)*(c(2)+1))-1

c(4)=)(b(4)+1)*(c(3)+1))-1

c(5)=)(b(5)+1)*(c(4)+1))-1

How would i put these in a for statement? Again C goes until x, B goes until x2.

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

- Help others & share knowledge
- Earn cash & points
- Learn & ask questions

2 Comments

gowflow

```
Sub ForStatement()
Dim I As Long, J As Long, X As Long
Dim B(X), C(2 * X)
For I = 1 To X
For J = 0 To 4
C(I) = (B(I) + 1) * (C(J) + 1) - 1
Next J
Next I
End Sub
```

```
Const x2 = 5
'Const x = 12 'must be large enough to get through all the iterations... e.g., if x2 = 5, then x must be 12, if x2 = 10 then x must be 52, etc.
'as array c() is a function of array b(), it stand to reason that c() can be dynamic and allocate what it needs on the fly, thus the declaration,
'and the redim preserve statement
Sub forStmt()
Dim i As Long, j As Long, k As Long
Dim b(1 To x2) As Variant, c() As Variant
k = 1
For i = 1 To x2 - 2
For j = i To x2
ReDim Preserve c(k) As Variant
c(k) = IIf(j = i, b(j), (b(j) + 1) * (c(k - 1) + 1) - 1)
k = k + 1
Next j
Next i
End Sub
```

Cheers,

Dave

genFormula-r1.xlsm

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Title | # Comments | Views | Activity |
---|---|---|---|

Importing specific cell from Excel to MS Access | 17 | 51 | |

Need macro to assign two digit numbers to selected cells in Excel 2016 | 3 | 33 | |

LOOK FOR | 22 | 27 | |

Zip Codes Excel Spreadsheet | 4 | 22 |

How to get Spreadsheet Compare 2016 working with the 64 bit version of Office 2016

This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.

Course of the Month7 days, left to enroll

Join the community of 500,000 technology professionals and ask your questions.