Sequencia de Valores VBA

ismorfi

22-03-2017 17:25:55

Ola pessoal,

Preciso de uma ajudinha, eu não sei lidar muito bem com evento loop, while e afins.
Sequencia 01.jpg
Eu preciso realizar uma sequencia para os itens Período inicio e Período Final, respeitando a quantidade final, por exemplo o Primeiro item:

Numeração: 8389273 | Período Inicio: 1948178 | Período Final: 1956300 | Quantidade: 8122 (A quantidade é para saber quantas linhas serão necessárias para se chegar até 19556300)

A ideia é que ele pegue a 1º numeração, coloque em outra aba e faça a sequencia inicio e fim, terminando isso, pegue a 2º numeração e faça faça o mesmo processo, e assim até finalizar os itens.

Numeração - Sequencia Período
8389273 - 1948178
8389273 - 1948179
8389273 - 1948180
8389273 - 1948181

Podem me ajudar?
Sequencia de Dados 2.zip

ismorfi

23-03-2017 11:39:43

Ola Pessoal,

Consegui fazer uma "gambearra" que atendeu o processo hshshs

Vou listar o código. Tem como deixar mais simples esse processo?

Código: Selecionar todos


Sub Macro1()
    
    Dim lWorksheet          As Worksheet
    Dim IPercorrer As Long
    Dim lUltimaLinhaAtiva As Long
    Dim Linha As Long
    Dim Coluna As Long
    Dim Valor As Long
    
    Application.ScreenUpdating = False
    
    lUltimaLinhaAtiva = Worksheets("Plan1").Cells(Worksheets("Plan1").Rows.Count, 3).End(xlUp).Row
    
    For Linha = 2 To lUltimaLinhaAtiva
    
    ThisWorkbook.Sheets("Plan1").Activate
    IPercorrer = Worksheets("Plan1").Range(Cells(Linha, 6), Cells(Linha, 6)).Value + 2
    Worksheets("Plan1").Range(Cells(Linha, 3), Cells(Linha, 5)).Select
    Selection.Copy
    
    
    ThisWorkbook.Sheets("Plan2").Select
    Range("A2").Select
    Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
        :=False, Transpose:=False
    
    Range("A2").Select
    Application.CutCopyMode = False
    Selection.Copy
    Selection.AutoFill Destination:=Range("A2:A" & IPercorrer), Type:=xlFillDefault
    

    Range("B2").Select
    Application.CutCopyMode = False
    Selection.AutoFill Destination:=Range("B2:B" & IPercorrer), Type:=xlFillSeries
    
    Call Macro2
    Call Macro5
    
    Next Linha
    
    MsgBox ("Processo Concluido")
    
End Sub


Sub Macro2()
    
    ThisWorkbook.Sheets("Plan2").Select
    Range("A2").Select
    Range(Selection, Selection.End(xlToRight)).Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Copy
    
    ThisWorkbook.Sheets("Plan3").Select
    
    Range("A1000000").End(xlUp).Offset(1, 0).Select
    ActiveCell.Offset(0, 0).Select
    ActiveSheet.Paste
    
End Sub

Sub Macro5()
    
    ThisWorkbook.Sheets("Plan2").Select
    Rows("2:2").Select
    Range(Selection, Selection.End(xlDown)).Select
    Selection.Delete Shift:=xlUp
    Application.CutCopyMode = False
    
    ThisWorkbook.Sheets("Plan1").Select
    
End Sub