Home > Software engineering >  Consult vba exhaustive array
Consult vba exhaustive array

Time:11-12

Sub text ()
Dim I As an Integer, j As an Integer, As an Integer k, l, As an Integer
Dim arr ()
Arr ()=Range (" a1: a48 ")
For I=1 To 48
For j=1 To 48
For k=1 To 48
For l=1 To 48
If arr (I, 1) + arr (j, 1) + arr (k, 1) + arr (l, 1)=664.04 Then
Range (" d3 ")=arr (I, 1)
Range (" e3 ")=arr (j, 1)
Range (" f3 ")=arr (k, 1)
G3 Range (" ")=arr (l, 1)
End the If
Next
Next
Next
Next
End Sub

Want to violence and exhaustive four number, why sometimes ask out sometimes not to come out again? The small white, thank you all for the great god

CodePudding user response:

 Sub demo () 
Dim I As an Integer, j As an Integer, As an Integer k, l, As an Integer
Dim arr ()
Arr ()=Range (" a1: a48 "). The Value
For I=1 To 48-3
For j=I - 2 To 48
For k=j To 48-1
For l=To 48 k
If arr (I, 1) + arr (j, 1) + arr (k, 1) + arr (l, 1)=664.04 Then
Range (" d3 ")=arr (I, 1)
Range (" e3 ")=arr (j, 1)
Range (" f3 ")=arr (k, 1)
G3 Range (" ")=arr (l, 1)
End the If
Next l
Next k
Next j
Next I
End Sub

CodePudding user response:

 Sub demo () 
Dim I As an Integer, j As an Integer, As an Integer k, l As an Integer, the index As an Integer
The index=1
Dim arr ()
Arr ()=Range (" a1: a48 "). The Value
For I=1 To 48-3
For j=I - 2 To 48
For k=j To 48-1
For l=To 48 k
If arr (I, 1) + arr (j, 1) + arr (k, 1) + arr (l, 1)=664 Then
Range (" d "& amp; The index)=arr (I, 1)
Range (" e "& amp; The index)=arr (j, 1)
Range (" f "& amp; The index)=arr (k, 1)
Range (" g "& amp; The index)=arr (l, 1)
The index=index + 1
End the If
Next l
Next k
Next j
Next I
End Sub

CodePudding user response:

reference 1st floor humanmagic response:
 Sub demo () 
Dim I As an Integer, j As an Integer, As an Integer k, l, As an Integer
Dim arr ()
Arr ()=Range (" a1: a48 "). The Value
For I=1 To 48-3
For j=I - 2 To 48
For k=j To 48-1
For l=To 48 k
If arr (I, 1) + arr (j, 1) + arr (k, 1) + arr (l, 1)=664.04 Then
Range (" d3 ")=arr (I, 1)
Range (" e3 ")=arr (j, 1)
Range (" f3 ")=arr (k, 1)
G3 Range (" ")=arr (l, 1)
End the If
Next l
Next k
Next j
Next I
End Sub

Can you explain why this

CodePudding user response:

 Sub demo () 
Dim I As an Integer, j As an Integer, As an Integer k, l As an Integer, arr
Dim index As an Integer
The index=1 'results counter
Arr ()=Range (" a1: a48 "). The Value
For I=1 To 48-3 'number exhaustion, a total of 48 points, 4 To 3
'j=I + 1 is to prevent a repeat options, such as the I chose number first, then j certainly cannot choose the first number
For j=I + 1-2 To 48
The above '
For k=j + 1 To 48-1
The above '
For l=k + 1 To 48
If arr (I, 1) + arr (j, 1) + arr (k, 1) + arr (l, 1)=664.04 Then
Range (" d "& amp; The index)=arr (I, 1)
Range (" e "& amp; The index)=arr (j, 1)
Range (" f "& amp; The index)=arr (k, 1)
Range (" g "& amp; The index)=arr (l, 1)
The index=index + 1 'counter + position increase
End the If
Next l
Next k
Next j
Next I
End Sub

CodePudding user response:

The
reference 4 floor humanmagic reply:
 Sub demo () 
Dim I As an Integer, j As an Integer, As an Integer k, l As an Integer, arr
Dim index As an Integer
The index=1 'results counter
Arr ()=Range (" a1: a48 "). The Value
For I=1 To 48-3 'number exhaustion, a total of 48 points, 4 To 3
'j=I + 1 is to prevent a repeat options, such as the I chose number first, then j certainly cannot choose the first number
For j=I + 1-2 To 48
The above '
For k=j + 1 To 48-1
The above '
For l=k + 1 To 48
If arr (I, 1) + arr (j, 1) + arr (k, 1) + arr (l, 1)=664.04 Then
Range (" d "& amp; The index)=arr (I, 1)
Range (" e "& amp; The index)=arr (j, 1)
Range (" f "& amp; The index)=arr (k, 1)
Range (" g "& amp; The index)=arr (l, 1)
The index=index + 1 'counter + position increase
End the If
Next l
Next k
Next j
Next I
End Sub

Exhaustion can't repeat? If I repeated four Numbers are? Even if not to come out?

CodePudding user response:

Repeat means four number are to choose a number

CodePudding user response:

refer to 6th floor humanmagic response:
duplicate mean all choose a number four number

I know, I mean four number are all the same it's not that I don't come out?

CodePudding user response:

refer to 6th floor humanmagic response:
duplicate mean all choose a number four number

Brother, I to you the code, some still don't come out

CodePudding user response:

Code itself is no problem, it is 48 48 48 * * * 48 a little big, so it is slow

CodePudding user response:

If only ask come out right, break out?

CodePudding user response:

references 9 f weixin_45903952 response:
code itself has no problems, 48 48 48 * * * is 48 is a little big, so really slow

No, sometimes seek out soonnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  •  Tags:  
  • VBA
  • Related