Logo 
Search:

MS Office Answers

Ask Question   UnAnswered
Home » Forum » MS Office       RSS Feeds
  Question Asked By: Rabiah Begum    on Dec 16 In MS Office Category.

  
Question Answered By: Anthony Smith   on Dec 16

Sounds like you need recursion! Basically you need a function (or
subroutine) which will loop through each of the possible values  for a
given cell, but each time it changes the value in that cell, it calls
itself for the next cell. Within that function, you need some way to
test for completion, i.e. when it gets to the last cell. The code
below will run  your combinations  in the cells  of row 1:

Const MIN = -10
Const MAX = 10

Sub RunCombinations()
RunCellValues 5, 1 ' change first value to your liking
End Sub

Sub RunCellValues(ByVal iCount As Integer, ByVal iIndex As Integer)

Dim ivalue As Integer

If iIndex <= iCount Then
For ivalue = MIN To MAX
Cells(1, iIndex).Value = ivalue
RunCellValues iCount, iIndex + 1
Next ivalue
End If

End Sub

Share: 

 

This Question has 2 more answer(s). View Complete Question Thread

 
Didn't find what you were looking for? Find more on How to run combinations Or get search suggestion and latest updates.


Tagged: