Boa tarde, amigo @fabio-cmaa
Teste o seguinte código:
Sub SintetizaPlan()
Dim ws As Worksheet, rg As Range, i As Long, cabeçalho As Variant
With ThisWorkbook
.Worksheets("ORIGANAL").Copy After:=.Worksheets(.Worksheets.Count)
Set ws = .ActiveSheet
End With
Set rg = Intersect(ws.Columns("A"), ws.UsedRange)
On Error Resume Next
rg.SpecialCells(xlCellTypeBlanks).EntireRow.Delete xlUp
On Error GoTo 0
For i = rg.Rows.Count To 1 Step -1
With rg.Rows(i)
If Len(.Value) <> 284 Or Not (.Value Like (Space(21) & "######" & Space(7) & "*")) Then
.EntireRow.Delete xlUp
End If
End With
Next i
rg.TextToColumns Destination:=ws.Range("B2"), _
DataType:=xlFixedWidth, TrailingMinusNumbers:=True, _
FieldInfo:=Array(Array(0, xlSkipColumn), _
Array(17, xlGeneralFormat), _
Array(27, xlSkipColumn), _
Array(31, xlGeneralFormat), _
Array(41, xlSkipColumn), _
Array(48, xlGeneralFormat), _
Array(56, xlSkipColumn), _
Array(66, xlGeneralFormat), _
Array(73, xlSkipColumn), _
Array(83, xlTextFormat), _
Array(98, xlTextFormat), _
Array(109, xlSkipColumn), _
Array(115, xlDMYFormat), _
Array(125, xlTextFormat), _
Array(139, xlGeneralFormat), _
Array(153, xlGeneralFormat), _
Array(169, xlGeneralFormat), _
Array(185, xlGeneralFormat), _
Array(205, xlGeneralFormat), _
Array(224, xlGeneralFormat), _
Array(243, xlGeneralFormat), _
Array(264, xlGeneralFormat), _
Array(284, xlSkipColumn))
cabeçalho = Array("Nº Pesagem", "Hr.Entrada", "Hr.Saída", "Hora NF", "Nº Ord. Carreg.", "N.F.", _
"Dt. Movto", "Caminhão", "1º Reboque", "2º Reboque", "Peso Emb.", "Peso Tara", _
"Peso Bruto", "Peso Líquido", "Líquido sem Emb.", "Quantidade")
ws.Range("B1:Q1").Value = cabeçalho
rg.EntireColumn.Delete xlShiftToLeft
ws.ListObjects.Add xlSrcRange, ws.Range("A1").CurrentRegion, , xlYes
ws.Range("A1").CurrentRegion.EntireColumn.AutoFit
End Sub
Postado : 09/09/2020 3:00 pm