Generate A array of columns, A2 is known! A (n)=RANDBETWEEN (50, 50)/5 + A2, n starting from 3, if A (n) - A (n - 1) & lt; 3 run A (n + 1), if not satisfied, recount A (n), could you tell me the VBA how to write! The younger brother to programming basic don't understand, so also please masters to help you,
CodePudding user response:
Dim n As Integer x As SingleN=3
Do
Do
X=RANDBETWEEN (50, 50)/5
Loop Until (x & gt; 0) And (x & lt; 3)
Range (" A "& amp; N)=Range (" A "& amp; N - 1) + x
N=n + 1
Loop Until x=300
CodePudding user response:
In fact, can be more simple,Dim n As Integer x As Single
N=3
Do
X=RANDBETWEEN (0, 15)/5
Range (" A "& amp; N)=Range (" A "& amp; N - 1) + x
N=n + 1
Loop Until x=300
CodePudding user response:
Please refer to:Option Explicit
Sub Test ()
As Single Dim I As an Integer, k, n As Single
With Sheet1
K=Sheet1. Range (" a2 ") 'this remained the same?
For I=3 To 300
Do
"' - 50 ~ 50 can as 0 ~ 100-50
N=(Rnd * 101-50)/5 + k
If n - k & lt; 3 Then
The Range (" a "& amp; I)=n
The Range (" a "& amp; I). NumberFormatLocal="_" 0.00 "' set the format
The Exit Do
End the If
Loop
Next
End With
End Sub
.