Segue o código completo:
Sub importarCerto()
'
' importarCerto Macro
'
'
Dim retornaValor As Boolean
Dim planilhaExterna As Workbook
Dim planilhaExterna2 As Workbook
Dim planilhaExterna3 As Workbook
Dim planilhaPrincipal As Workbook
Set planilhaPrincipal = ActiveWorkbook
retornaValor = Application.Dialogs(xlDialogOpen).Show("*.xls")
If retornaValor = False Then
MsgBox "Falha ao carregar a planilha"
Exit Sub
Else
End If
Set planilhaExterna = ActiveWorkbook
Columns("A:E").Select
Selection.Copy
planilhaPrincipal.Activate
planilhaPrincipal.Sheets("Plan1").Select
Cells.Select
Cells.Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Range("B2").Select
retornaValor = Application.Dialogs(xlDialogOpen).Show("*.xls")
If retornaValor = False Then
MsgBox "Falha ao carregar a planilha"
Exit Sub
Else
End If
Set planilhaExterna2 = ActiveWorkbook
Columns("A:D").Select
Application.CutCopyMode = False
Selection.Copy
planilhaPrincipal.Activate
planilhaPrincipal.Sheets("Plan2").Select
Cells.Select
Range("A1").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
retornaValor = Application.Dialogs(xlDialogOpen).Show("*.xls")
If retornaValor = False Then
MsgBox "Falha ao carregar a planilha"
Exit Sub
Else
End If
Set planilhaExterna3 = ActiveWorkbook
Columns("A:D").Select
Application.CutCopyMode = False
Selection.Copy
planilhaPrincipal.Activate
planilhaPrincipal.Sheets("Plan3").Select
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Sheets("Plan1").Select
Columns("A:E").Select
Columns("A:E").EntireColumn.AutoFit
Sheets("Plan2").Select
Columns("A:D").Select
Columns("A:D").EntireColumn.AutoFit
Sheets("Plan3").Select
Columns("A:D").Select
Columns("A:D").EntireColumn.AutoFit
Sheets("Plan1").Select
'Juntando tudo
Dim linha As Integer
linha = 1
Sheets("Plan1").Select
Range("A1").Select
Do
ActiveCell.Offset(1, 0).Select
Loop Until IsEmpty(ActiveCell.Offset(0, 0).Value)
Do
ActiveCell.Offset(0, 0).Value = Sheets("Plan2").Cells(i, 1).Value
ActiveCell.Offset(0, 1).Value = Sheets("Plan2").Cells(i, 2).Value
ActiveCell.Offset(0, 2).Value = Sheets("Plan2").Cells(i, 3).Value
linha = linha + 1
Loop Until IsEmpty(Sheets("Plan2").Cells(i, 3).Value)
End Sub
Postado : 23/06/2017 1:05 pm