Bom dia jlvdranca,
Vê se ajuda:
Option Explicit
Sub Macro1()
Dim wsAtiva As Worksheet
Dim sArquivo As String
Dim UltL As Long
Dim i As Long
Application.ScreenUpdating = False
sArquivo = CStr(Application.GetOpenFilename("Arquivo de Texto (*.TXT*),*.TXT*", , "Selecione um arquivo *.TXT*:", , False))
If sArquivo = "Falso" Then
MsgBox "Arquivo não selecionado"
Exit Sub
End If
ThisWorkbook.Worksheets.Add After:=ThisWorkbook.Worksheets(ThisWorkbook.Worksheets.Count)
Set wsAtiva = ThisWorkbook.ActiveSheet
With wsAtiva.QueryTables.Add(Connection:= _
"TEXT;" & sArquivo, Destination:=Range("$A$1"))
.TextFileParseType = xlDelimited
.TextFileOtherDelimiter = "|"
.TextFileColumnDataTypes = Array(2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2)
.Refresh
End With
UltL = wsAtiva.Cells(Rows.Count, 1).End(xlUp).Row
ActiveWorkbook.Connections(1).Delete
ActiveWorkbook.Names(1).Delete
For i = 5 To UltL
If Not wsAtiva.Cells(i, 1).Value = "BPFDEC" Then
wsAtiva.Range("A" & i & ":C" & i).Insert Shift:=xlToRight, CopyOrigin:=xlFormatFromLeftOrAbove
wsAtiva.Range("A" & i - 1 & ":C" & i - 1).AutoFill Destination:=wsAtiva.Range("A" & i - 1 & ":C" & i), Type:=xlFillCopy
End If
Next i
Application.ScreenUpdating = True
MsgBox "Processo finalizado com sucesso"
End Sub
Qualquer coisa da o grito.
Abraço
Existem mil maneiras de preparar Neston. Invente a sua!
http://www.youtube.com/ExpressoExcel
Postado : 18/01/2017 8:02 am