Este fórum está sendo desativado

Depois de 9 anos, este fórum será desativado. Mas calma.... estamos migrando para uma comunidade no DISCORD. Junte-se a nós.

ENTRAR PARA DISCORD

Tópicos relacionados a códigos VBA, gravação de macros, etc.
Por heko
#53662
Amigos, boa noite.

Criei o código abaixo para calcular os divisores de qualquer número. Ocorre que ele apresenta todos os divisores do número numa mesma célula. Por exemplo: Divisores do número 30 = 1; 2; 3; 5; 6; 10; 15; 30
O código retorna todos os divisores do número dado na célula A1.

Preciso que cada divisor seja apresentado em uma célula distinta.

Segue o código:

Function Divisores_GT(num As Long) As String

Dim i As Long
Dim retorno As String

retorno = 1
For i = 2 To num
If num Mod i = o Then retorno = retorno & "; " & i
Next i

Divisores_GT = retorno

End Function

Sub testar()
Selection.Range("A1").Value = Divisores_GT(30)
End Sub

Obrigado
Por babdallas
#53663
Veja se isso ajuda.
Código: Selecionar todos
Public Sub Divisores_GT(lngNumero As Long, rngNum As Range)
    Dim lngCont     As Long
    Dim lngNum()    As Long
    Dim lngDiv      As Long
    
    If VBA.IsNumeric(lngNumero) Then
        ReDim lngNum(1 To 10) As Long
        lngNum(1) = 1
        lngDiv = 1
        For lngCont = 2 To lngNumero
            If lngNumero Mod lngCont = 0 Then
                lngDiv = lngDiv + 1
                If lngDiv Mod 10 = 0 Then ReDim Preserve lngNum(1 To lngDiv * 10)
                lngNum(lngDiv) = lngCont
            End If
        Next lngCont
        ReDim Preserve lngNum(1 To lngDiv)
    End If
    
    rngNum.Resize(UBound(lngNum)).Value2 = Application.Transpose(lngNum())
End Sub

Sub testar()
    Divisores_GT 30, Planilha1.Range("A1")
End Sub
long long title how many chars? lets see 123 ok more? yes 60

We have created lots of YouTube videos just so you can achieve [...]

Another post test yes yes yes or no, maybe ni? :-/

The best flat phpBB theme around. Period. Fine craftmanship and [...]

Do you need a super MOD? Well here it is. chew on this

All you need is right here. Content tag, SEO, listing, Pizza and spaghetti [...]

Lasagna on me this time ok? I got plenty of cash

this should be fantastic. but what about links,images, bbcodes etc etc? [...]

Estamos migrando para uma comunidade no Discord