lundi 28 octobre 2019

VBA random function problem - not working when closing workfile

I made a code generator with random function, but it generates the same codes when closing and opening the macro again. When running macro more times on 1 opening, it works fine but when I close the file with macro, open again, It generates the same codes. It is something like this - example:

  1. open excel file, generated: 1111, generated: 2222, close
  2. open file with macro, generated: 1111, generated 2222, generated 3333 close worksheet
  3. Open file, generated: 1111

      For i = 15 To 38
      ws2.Cells(i, 2) = Int((9999 - 0 + 1) * Rnd + 0)
      ws2.Cells(i, 3) = Int((9999 - 0 + 1) * Rnd + 0)
      ws2.Cells(i, 4) = Int((9999 - 0 + 1) * Rnd + 0)
      ws2.Cells(i, 5) = Int((9999 - 0 + 1) * Rnd + 0)
      ws2.Cells(i, 6) = Int((9999 - 0 + 1) * Rnd + 0)
      ws2.Cells(i, 7) = Int((9999 - 0 + 1) * Rnd + 0)
      ws2.Cells(i, 8) = Int((9999 - 0 + 1) * Rnd + 0)
      ws2.Cells(i, 9) = Int((9999 - 0 + 1) * Rnd + 0)
      ws2.Cells(i, 10) = Int((9999 - 0 + 1) * Rnd + 0)
      ws2.Cells(i, 11) = Int((9999 - 0 + 1) * Rnd + 0)
      ws2.Cells(i, 12) = Int((9999 - 0 + 1) * Rnd + 0)
      ws2.Cells(i, 13) = Int((9999 - 0 + 1) * Rnd + 0)
    
      Next i
    

Expected result (example):

  1. open file, generate: 1111, generate: 2222, close
  2. open file with macor, generated: 3333, generated 4444, generated 5555 close worksheet
  3. Open file, generated: 6666



Aucun commentaire:

Enregistrer un commentaire