Saltar al contenido
PROGRAMAR EN VBA MACROS DE EXCEL

Formulario inserta numeros aleatorios


.

Sencillo código que agrega números aleatorios menor al indicado en el formulario de ingreso de datos.

Private Sub CommandButton1_Click()
Dim limsup, liminf, ram, fila As Integer
Dim sum, sumT, num As Currency
num = TextBox1.Value
limsup = num
liminf = 0
fila = 2
sum = 0
sumT = 0

 For x = 2 To 30

If sumT <= num Then
 limsup = num – sumT
 ram = Int((limsup – liminf + 1) * Rnd + liminf)
 Sheets(«hoja1»).Cells(x, 1) = ram
 sum = Sheets(«hoja1»).Cells(x, 1)
 sumT = sumT + sum

Else
 Sheets(«hoja1»).Cells(x, 1) = 0
End If
 Next
End Sub
Private Sub CommandButton2_Click()
Unload Me
End Sub

Si te fue de utilidad puedes INVITARME
UN CAFÉ
 y de esta manera ayudar a seguir
manteniendo la página, CLICK para descargar en ejemplo en forma gratuita.


.

If this post was
helpful INVITE ME A COFFEE and so help keep
up the page, CLICK to download free example.

Si te gustó por favor compártelo con tus amigos
If you liked please share it with your friends