Notifications
Clear all

JUNTAR DUAS MACRO PARA EXECUTAR NO MESMO COMANDO

2 Posts
1 Usuários
0 Reactions
811 Visualizações
(@fragosojp)
Posts: 0
New Member
Topic starter
 

boa tarde a todos,

preciso de uma ajuda de vocês,
eu tenho duas macros e atualmente tenho que executar uma de cada vez!
gostaria da ajuda de vocês para juntar as duas macros para que executasse em um comando só

primeira macro insere a data atual sem uma linha abaixo

Sub INSERIR_DATA_()

    Cells(Rows.Count, "B").End(xlUp).Offset(1).Value = Date & " - Relatório"

End Sub

Segunda macro copia os valores da plan1 para a plan2
Sub Copiar2()
  Dim LR As Long 'retorna o número da última linha com conteúdo na coluna
    LR = Sheets("Plan2").Cells(Rows.Count, 1).End(xlUp).Row
  Sheets("Plan1").Range("D5").Copy Sheets("Plan2").Range("A" & LR + 1)
 Sheets("Plan1").Range("f4").Copy Sheets("Plan2").Range("F" & LR + 1)
  
    LR = Sheets("Plan2").Cells(Rows.Count, 1).End(xlUp).Row
  Sheets("Plan1").Range("C28:H53").Copy Sheets("Plan2").Range("A" & LR + 1)
End Sub

segue a planilha como modelo

 
Postado : 28/04/2017 11:31 am
(@fragosojp)
Posts: 0
New Member
Topic starter
 

eu consegui juntar aqui
depois de muitas tentativas e erros deu certo

segue o código correto

Sub Copiar2()

Plan2.Cells(Rows.Count, "B").End(xlUp).Offset(1).Value = Date & " - Relatório"

  Dim LR As Long 'retorna o número da última linha com conteúdo na coluna
    LR = Sheets("Plan2").Cells(Rows.Count, 1).End(xlUp).Row
  Sheets("Plan1").Range("D5").Copy Sheets("Plan2").Range("A" & LR + 1)
 Sheets("Plan1").Range("f4").Copy Sheets("Plan2").Range("F" & LR + 1)
  
    LR = Sheets("Plan2").Cells(Rows.Count, 1).End(xlUp).Row
  Sheets("Plan1").Range("C28:H53").Copy Sheets("Plan2").Range("A" & LR + 1)
End Sub
 
Postado : 28/04/2017 11:50 am