Saltar al contenido
View in the app

A better way to browse. Learn more.

Ayuda Excel

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

crear lista en excel mediante VBA entre dos números definidos por el usuario.

publicado

Hola, me gustaría crear una lisa a partir dos valores dados por el usuario mediante dos inputbox.

de momento tengo esto:

 

 

Sub inputbox_granalcancelista()
    Dim i As Long
    Dim a As Long
    
    
    i = InputBox("introduce el número inicial", "LISTA NÚMEROS", "type here")
    a = InputBox("introduce el número final", "LISTA NÚMEROS", "type here")
    
    Range("A1").Value = i
    
   [AQUÍ NO SÉ QUÉ AÑADIR]
    
    
End Sub
 

Featured Replies

publicado

 

Private Sub CommandButton1_Click()
    Dim i As Long
    Dim a As Long

    i = InputBox("introduce el número inicial", "LISTA NÚMEROS", "type here")
    a = InputBox("introduce el número final", "LISTA NÚMEROS", "type here")
    n = a - i
    
    For x = 1 To n + 1
        Cells(x, 1) = i + (x - 1)
    Next x
    
End Sub

Te dejo una posible solución

Prueba.gif

Prueba 1.xlsm

publicado
  • Autor

¡¡MUCHAS GRACIAS!!

me gustaría saber tambien, como ahora estos números ( los de la lista) cumplen o no una condición, es decir, si cumplen o no una funcion VBA que ya tengo programada. Y una vez sabido, que me escriba aquellos que sí cumplen la condición.

--->esta es la función que he programado:

Function granalcance(numero As Long) As Boolean
    
    Dim factor As Long
    Dim multip As Long
    Dim resto As Long
    

    factor = 2
    resto = numero

    If numero = 1 Then
    End If
    Do Until resto = 1
        If resto Mod factor = 0 Then
            multip = 1
            Do
                multip = multip + 1
                
                
                
                DoEvents
            Loop While resto \ factor Mod factor ^ (multip - 1) = 0
            
            If multip > 2 Then
                granalcance = True
            
            Else
                granalcance = False
                
            End If
            
            resto = resto \ factor ^ (multip - 1)
        End If
        
        
        If resto <> 1 Then
            factor = factor + 1
        End If
        
    DoEvents
    Loop

End Function

 

Espero haberme explicado,  gracias.

publicado
Private Sub CommandButton1_Click()
   Dim i As Long
   Dim a As Long
   Dim x As Long
   
   Application.ScreenUpdating = False
   i = InputBox("introduce el número inicial", "LISTA NÚMEROS")
   a = InputBox("introduce el número final", "LISTA NÚMEROS")
   Columns(1).ClearContents
   For i = i To a
     If GranAlcance(i) Then
        x = x + 1
        Cells(x, 1) = i
      End If
   Next
    
End Sub

Y la función:

Function GranAlcance(numero As Long) As Boolean
   Dim factor As Long
   Dim multip As Long
   Dim resto As Long
   
   factor = 2
   resto = numero
   
   Do Until resto = 1
      If resto Mod factor = 0 Then
          multip = 1
          Do
              multip = multip + 1
          Loop While resto \ factor Mod factor ^ (multip - 1) = 0
          If multip > 2 Then
              GranAlcance = True
              Exit Function
          End If
          resto = resto \ factor ^ (multip - 1)
      End If
      If resto <> 1 Then factor = factor + 1
   Loop
End Function

 

Archivado

Este tema está ahora archivado y está cerrado a más respuestas.

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.