Bom dia gente, tudo bem?
Preciso de um help com uma planilha, por favor. Criei uma macro para exportar um arquivo de texto, separado por ';', porém, tenho 2 problemas:
1- Todas as linhas saem entre aspas.
Exemplo: "I;34009;3;213,02;1;1"
2- Está listando todas as linhas da tabela, mesmo que não tenha informação.
Exemplo:
"I;34009;3;213,02;1;1"
"I;38496;2;91,98;2;2"
";;;;;"
";;;;;"
Minha fórmula é essa aqui:
Sub ExportarParaTXT()
Dim i As Integer, j As Integer, a As Integer, t As Integer, y As Integer
Dim caminho As String, nomearquivo As String
Dim linha As String
Dim linha2 As String
caminho = "\\red1\Geral\Backup\"
nomearquivo = "VENDAS.txt"
a = FreeFile
Open caminho & nomearquivo For Output As #a
With Worksheets("EXPORT")
For t = 1 To .Range("a1").End(xlToRight).Row
For y = 1 To .Range("a1").End(xlToRight).Column
If y = 1 Then
linha2 = .Range("a1").Cells(t, y)
ElseIf y <> t Then
linha2 = linha2 & ";" & .Range("a1").Cells(t, y)
End If
Next y
Write #a, linha2
Next t
With Worksheets("EXPORT")
For i = 1 To .Range("a4").End(xlDown).Row
For j = 1 To .Range("a4").End(xlToRight).Column
If j = 1 Then
linha = .Range("a4").Cells(i, j)
ElseIf j <> 1 Then
linha = linha & ";" & .Range("a4").Cells(i, j)
End If
Next j
Write #a, linha
Next i
End With
End With
Close #a
End Sub
Alguém consegue me ajudar? rs