Notifications
Clear all

Problema com loop

4 Posts
2 Usuários
0 Reactions
940 Visualizações
(@amaration)
Posts: 15
Eminent Member
Topic starter
 

boa tarde,

Possuo 13 planilhas: 12 com os nomes dos meses (JANEIRO a DEZEMBRO) e a Plan13.

Na plan13 estou tentando colar dados que se repetem das outras planilhas. já escrevi esse código abaixo.

Minha dúvida é, tem como colocar um loop ao final do código (depois do Line0) enviando sempre pra próxima line? Tipo, quando chegar no final, roda o Line3, depois quando chegar no final novamente, roda o Line4, até o 13... Tem como fazer isso???

Sheets("JANEIRO").Select
GoTo Line1
Line3:
Sheets("FEVEREIRO").Select
GoTo Line1
Line4:
Sheets("MARÇO").Select
GoTo Line1
Line5:
Sheets("ABRIL").Select
GoTo Line1
Line6:
Sheets("MAIO").Select
GoTo Line1
Line7:
Sheets("JUNHO").Select
GoTo Line1
Line8:
Sheets("JULHO").Select
GoTo Line1
Line9:
Sheets("AGOSTO").Select
GoTo Line1
Line10:
Sheets("SETEMBRO").Select
GoTo Line1
Line11:
Sheets("OUTUBRO").Select
GoTo Line1
Line12:
Sheets("NOVEMBRO").Select
GoTo Line1
Line13:
Sheets("DEZEMBRO").Select
GoTo Line1

Line1:
If Range("G16").Value = "" Then
Range("G15:H15").Select
GoTo Line0
Else
Range("G15:H15").Select
Range(Selection, Selection.End(xlDown)).Select
GoTo Line0
End If
Line0:
Application.CutCopyMode = False
Selection.Copy
Sheets("Plan13").Select
Columns("AH:AH").Select
c = Selection.Find(What:="", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

 
Postado : 21/06/2014 12:48 pm
(@fernandofernandes)
Posts: 43750
Illustrious Member
 

Não entendi???

 
Postado : 21/06/2014 1:35 pm
(@amaration)
Posts: 15
Eminent Member
Topic starter
 

De forma resumida, o código

If Range("G16").Value = "" Then
Range("G15:H15").Select

Application.CutCopyMode = False
Selection.Copy
Sheets("Plan13").Select
Columns("AH:AH").Select
c = Selection.Find(What:="", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

Else
Range("G15:H15").Select
Range(Selection, Selection.End(xlDown)).Select

Application.CutCopyMode = False
Selection.Copy
Sheets("Plan13").Select
Columns("AH:AH").Select
c = Selection.Find(What:="", After:=ActiveCell, LookIn:=xlValues, LookAt _
:=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
False, SearchFormat:=False).Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False

End If

Se repete após cada Sheets("MÊS").Select

gostaria de saber se MÊS pode ser uma variável que rode a macro pra cada valor de JANEIRO a DEZEMBRO.... tipo um loop

Deu pra entender agora, ou ainda tá confuso?

 
Postado : 21/06/2014 1:48 pm
(@amaration)
Posts: 15
Eminent Member
Topic starter
 

Consegui resolver sozinha... Nas células AM1:AM12 listei os meses, depois rodei a macro:

Sub teste()
Dim h

For h = 1 To 12
a = Range("AM" & h).Value

Sheets(a).Select
   
    If Range("G16").Value = "" Then
    Range("G15:H15").Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("Plan13").Select
        Columns("AH:AH").Select
        c = Selection.Find(What:="", After:=ActiveCell, LookIn:=xlValues, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    Else
    Range("G15:H15").Select
    Range(Selection, Selection.End(xlDown)).Select
        Application.CutCopyMode = False
        Selection.Copy
        Sheets("Plan13").Select
        
        Columns("AH:AH").Select
        c = Selection.Find(What:="", After:=ActiveCell, LookIn:=xlValues, LookAt _
            :=xlPart, SearchOrder:=xlByRows, SearchDirection:=xlNext, MatchCase:= _
            False, SearchFormat:=False).Select
        Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
            :=False, Transpose:=False
    End If


Next h
End Sub
 
Postado : 21/06/2014 3:15 pm