Fiz algumas alteracoes no codigo do meu arquivo. Descobri que em cada planilha a ultima linha de dados estava sendo substituida pelos dados do proximo arquivo importado. Abaixo esta a parte que alterei:
If Range("A1048576").End(xlUp).Value = "" Then
Range("A1048576").End(xlUp).Select
Else: Range("A1048576").End(xlUp).Select
ActiveCell.Offset(1, 0).Select
End If
ActiveSheet.Paste
Tambem consegui fazer a macro pra colocar o nome da planilha de acordo com a quantidade de dados de cada planilha usando o "monstrinho" abaixo. Sera que poderiam me dar umas dicas de como melhorar isso?:
Sub LinhaA1()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("A-1").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaA2()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("A-2").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaA3()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("A-3").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaA4()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("A-4").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaA5()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("A-5").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaA6()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("A-6").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaA7()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("A-7").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaA8()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("A-8").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaA9()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("A-9").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaAA()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("A-A").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaB1()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("B-1").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaB2()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("B-2").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaB3()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("B-3").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaB4()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("B-4").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaB5()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("B-5").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaB6()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("B-6").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaB7()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("B-7").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaB8()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("B-8").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaB9()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("B-9").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaBA()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("B-A").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaBB()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("B-B").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub LinhaBC()
Dim XI As Long
Application.Workbooks("★取込まとめ").Worksheets("B-C").Activate
For XI = 2 To 1048576 Step 1
If ActiveSheet.Cells(XI, 7).Value = "" Then
ActiveSheet.Cells(XI, 1).Select
Exit Sub
Else: ActiveSheet.Cells(XI, 13).Value = ActiveSheet.Name
End If
Next XI
End Sub
Sub Chama()
Call LinhaA1
LinhaA2
LinhaA3
LinhaA4
LinhaA5
LinhaA6
LinhaA7
LinhaA8
LinhaA9
LinhaAA
LinhaB1
LinhaB2
LinhaB3
LinhaB4
LinhaB5
LinhaB6
LinhaB7
LinhaB8
LinhaB9
LinhaBA
LinhaBB
LinhaBC
End Sub
Estou incluindo outro arquivo chamado "arquivodados". Esse arquivo seria aquele que eu vou receber todos os dias e de onde eu devo importar os dados. A tabela comeca a partir da linha 9 e por isso no momento estou tendo que apagar as 8 primeira linhas de cada planilha antes de comecar a importacao. Gostaria de pedir uma dica nessa parte para incluir esse procedimento no codigo. Pensei em definir a area a ser copiada pegando a area da linha9 ate a ultima linha usada, porem nao estou conseguindo definir a ultima linha usada. No momento a area a ser copiada esta definida atras do codigo abaixo:
ActiveSheet.UsedRange.Select
Selection.Copy
Agradeco e espero ancioso por qualquer dica e ajuda. Vlw.
Postado : 19/07/2012 5:49 pm