I have some code below that generates some random numbers in Excel:
Sub Macro1()
Dim RA1 As Variant
ReDim RA1(1 To 5)
For i = 1 To 5
Rnd (-1)
Randomize i
For j = 1 To 5
RA1(j) = Rnd
Next j
With Sheets("Sheet1")
.Range(Cells(i, 1), Cells(i, 5)).Value = RA1
End With
Next i
End Sub
This code basically generates 5 rows of 5 random numbers, but it is not running exactly as it should. When I run this code on my iMac (2021), the random numbers in each row are exactly the same. However, what this code should be generating are 5 different rows of random numbers.
Here is where things become even weirder. When I run this code on my Windows laptop, the output is as desired - that is, I do indeed get 5 different rows of random numbers. I have spoken to my professor about this and he has tried it on his Windows computer too and got 5 different rows of random numbers.
We have come to the conclusion that it is some setting in my iMac's Excel that is preventing this code from running as it should. My professor also suspects that it is not inherently an Apple issue, since he says no one has come to him with this problem before.
All in all, we basically do not know why my iMac is unable to run this code. Does anyone have any guesses as to why there is this discrepancy here? For example, are there any settings in my iMac's Excel that is preventing my code from running correctly?
Any explanations and solutions will be greatly appreciated! :)
Note: I have not changed any setting in my iMac's Excel before (well, at least, not that I know of), so everything should be default as of now.
Aucun commentaire:
Enregistrer un commentaire