Ir ao conteúdo
  • Cadastre-se

Macro para mudar de coluna a cada contagem


Posts recomendados

alguem ai que possa ajudar com vba?
o problema é: quero mudar de coluna, a cada contagem de linha.
ex.: a cada 100 linhas contadas, uma coluna.
eu consigo mudar de linha mas nao consigo mudar de coluna.
eis a situação do codigo:

 

Sub numberlist()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Dim a1 As Single
Dim b1 As Single
Dim c1 As Single
Dim d1 As Single
Dim e1 As Single
Dim f1 As Single
Dim g1 As Single
Dim h1 As Single
Dim i1 As Single
Dim j1 As Single
Dim count As Integer
Dim lrow As Long
Dim lcolumn As Integer

a1 = 0
b1 = 0
c1 = 0
d1 = 0
e1 = 0
f1 = 0
g1 = 0
h1 = 0
i1 = 0

    
    For a1 = 0 To 1 Step 1
    For b1 = 0 To 1 Step 1
    For c1 = 0 To 1 Step 1
    For d1 = 0 To 1 Step 1
    For e1 = 0 To 1 Step 1
    For f1 = 0 To 1 Step 1
    For g1 = 0 To 1 Step 1
    For h1 = 0 To 1 Step 1
    For i1 = 0 To 1 Step 1
    lrow = Cells(Rows.count, "A").End(xlUp).Row + 1
    Cells(lrow, "A") = a1 & b1 & c1 & d1 & e1 & f1 & g1 & h1 & i1 & j1
    
    If lrow Mod 100 = 0 Then
        Application.EnableEvents = False
        lcolumn = Range(1, Columns.count).Next(xlToRight).Column + 1
        lrow = 0
        lrow = Cells(Rows.count, Columns.count).End(xlUp).Row + 1
        Cells(lrow, "A") = a1 & b1 & c1 & d1 & e1 & f1 & g1 & h1 & i1 & j1
        Else
        End If
        
    Next
    
    Next
    Next
    Next
    Next
    Next
    Next
    Next
    Next
    
    
    
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
 

 

Link para o comentário
Compartilhar em outros sites

Se eu entendi

 

Sub Contador()

Dim a As Long
Dim linha As Long
Dim coluna As Long

linha = 2
coluna = 1
inicio:
For a = 1 To 100

Cells(linha, coluna) = a
linha = linha + 1

Next
coluna = coluna + 1
a = 1
linha = 2
If coluna = 15 Then 'Altere o 15 pelo numero da ultima coluna +1 que precisar  preencher se for a coluna 10 coloque 11
Exit Sub
Else
GoTo inicio
End If

End Sub

  • Curtir 1
Link para o comentário
Compartilhar em outros sites

Consegui!
funciona desta forma:
 

Sub numberlist()
Application.ScreenUpdating = False
Application.Calculation = xlCalculationManual

Dim a1 As Single
Dim b1 As Single
Dim c1 As Single
Dim d1 As Single
Dim e1 As Single
Dim f1 As Single
Dim g1 As Single
Dim h1 As Single
Dim i1 As Single
Dim j1 As Single
Dim count As Integer
Dim lrow As Long
Dim lcolumn As Long

a1 = 0
b1 = 0
c1 = 0
d1 = 0
e1 = 0
f1 = 0
g1 = 0
h1 = 0
i1 = 0
lcolumn = 1

    
    For a1 = 0 To 2 Step 1
    For b1 = 0 To 2 Step 1
    For c1 = 0 To 2 Step 1
    For d1 = 0 To 2 Step 1
    For e1 = 0 To 2 Step 1
    For f1 = 0 To 2 Step 1
    For g1 = 0 To 2 Step 1
    For h1 = 0 To 2 Step 1
    For i1 = 0 To 2 Step 1
    lrow = Cells(Rows.count, lcolumn).End(xlUp).Row + 1
    Cells(lrow, lcolumn) = a1 & b1 & c1 & d1 & e1 & f1 & g1 & h1 & i1 & j1
    
    If lrow Mod 1000 = 0 Then
               
        lcolumn = lcolumn + 1
        lrow = 1
        
        Else
        End If
        
    Next
    
    Next
    Next
    Next
    Next
    Next
    Next
    Next
    Next
    
    
    

Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub
 

Link para o comentário
Compartilhar em outros sites

  • mês depois...

Joás Lima, da uma olhada se te serve

 

Public Sub Contador_Linhas_Colunas()    'Conta as linhas e colunas com valores

    LinhaAtual = 1
    ColunaAtual = 1

    Do    'Para Colunas

        Do    'Para Linhas

            Worksheets("Plan2").Cells(LinhaAtual, ColunaAtual + 7).Value = _
            Worksheets("Plan2").Cells(LinhaAtual, ColunaAtual).Value

            LinhaAtual = LinhaAtual + 1
        Loop Until Worksheets("Plan2").Cells(LinhaAtual, ColunaAtual).Value = ""

        LinhaAtual = 2    'linha volta ao valor inicial
        ColunaAtual = ColunaAtual + 1

    Loop Until Worksheets("Plan2").Cells(LinhaAtual, ColunaAtual).Value = ""

End Sub

 

Public Sub Contador_Linhas_Colunas()   'Conta quantas linhas e ou colunas que você informa

    Dim x, y As Integer

    For x = 1 To 10    'Informe a quantidade de Colunas

 

        For y = 1 To 100    'Informe a quantidade de linhas

            Plan2.Cells(y, x).Value = y

'            y = y + 1

        Next y

 

'        x = x + 1

    Next x

End Sub

Link para o comentário
Compartilhar em outros sites

Visitante
Este tópico está impedido de receber novas respostas.

Sobre o Clube do Hardware

No ar desde 1996, o Clube do Hardware é uma das maiores, mais antigas e mais respeitadas comunidades sobre tecnologia do Brasil. Leia mais

Direitos autorais

Não permitimos a cópia ou reprodução do conteúdo do nosso site, fórum, newsletters e redes sociais, mesmo citando-se a fonte. Leia mais

×
×
  • Criar novo...