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.
  • Avatar do usuário
#69574
Oi pessoal,

Com alguma ajuda e pesquisa consegui criar esta macro, o que ela faz é ir buscar dados em uma planilha que vem de ser aberta.
Copia e fecha essa mesma planilha, o que preciso é que assim que fecha os proximos dados sejam copiados na seguinte linha.
ou sera preciso criar um loop?
podem ajudar? :)

Sub CopyOutput()
Dim wb1 As Workbook, wb2 As Workbook
Dim Ret1, Ret2
Dim linha As Double, coluna As Double


Set wb1 = ActiveWorkbook
'~~> Clear CopyData tab

'~~> Get the File
Ret1 = Application.GetOpenFilename("Excel Files (*.xls*), *.xls*", _
, "Please select file")
If Ret1 = False Then Exit Sub


Set wb2 = Workbooks.Open(Ret1)

If wb2.Sheets(1).Range("g7") <> "" Then


wb2.Sheets(1).Range("G6").Copy Destination:=wb1.Worksheets(1).Range("A4").Cells
wb2.Sheets(1).Range("s10").Copy Destination:=wb1.Worksheets(1).Range("b4").Cells
wb2.Sheets("final flight report").Range("i36").Copy Destination:=wb1.Worksheets(1).Range("c4").Cells
wb2.Sheets(1).Range("e41").Copy Destination:=wb1.Worksheets(1).Range("d4").Cells
wb2.Sheets("final flight report").Range("i66").Copy Destination:=wb1.Worksheets(1).Range("e4").Cells
wb2.Sheets(1).Range("e43").Copy Destination:=wb1.Worksheets(1).Range("h4").Cells
wb2.Sheets("final flight report").Range("j72").Copy Destination:=wb1.Worksheets(1).Range("m4").Cells
'wb2.Sheets(1).Range("D1:D13").Copy Destination:=wb1.Worksheets("Control").Range("B12:B27").Cells


wb2.Close SaveChanges:=False



Else
wb2.Close SaveChanges:=False
MsgBox "No data.", vbExclamation, "CIS"
End If

Set wb2 = Nothing
Set wb1 = Nothing
End Sub
#69578
Certo. Nesse caso precisamos pegar a última linha com registro para saber onde começar a incluir.
A planilha que você abre para copiar tem que fazer alguma validação de onde tem as informações ou só selecionar o intervalo e fazer a cópia?
#69582
Pelo código abaixo, sua rotina faz isso e sobrepõe os dados ao colar a cópia. A não ser que esteja fazendo manualmente os caminhos das células...

wb2.Sheets(1).Range("G6").Copy Destination:=wb1.Worksheets(1).Range("A4").Cells
wb2.Sheets(1).Range("s10").Copy Destination:=wb1.Worksheets(1).Range("b4").Cells
wb2.Sheets("final flight report").Range("i36").Copy Destination:=wb1.Worksheets(1).Range("c4").Cells
wb2.Sheets(1).Range("e41").Copy Destination:=wb1.Worksheets(1).Range("d4").Cells
wb2.Sheets("final flight report").Range("i66").Copy Destination:=wb1.Worksheets(1).Range("e4").Cells
wb2.Sheets(1).Range("e43").Copy Destination:=wb1.Worksheets(1).Range("h4").Cells
wb2.Sheets("final flight report").Range("j72").Copy Destination:=wb1.Worksheets(1).Range("m4").Cells
'wb2.Sheets(1).Range("D1:D13").Copy Destination:=wb1.Worksheets("Control").Range("B12:B27").Cells


Disponibiliza as planilhas com algumas poucas informações que te ajudo.
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