Tengo el siguiente código que me ayuda a exportar una columna cada 100 filas y guardar lo en una carpeta en formato .txt pero cada vez que exporto al final de la línea 100 se agrega un espacio en blanco, me pueden ayudar a quitarlo y que solo queden las 100 líneas que necesito.
Adjunto código:
Sub ExportarTXT()
Dim mPath$, iniCell$, i&, LR&, Vec, j%, iniTime!, R%
iniCell = "$G$2"
iniTime = Timer
mPath = ThisWorkbook.Path & "\Txt\"
With CreateObject("Scripting.FileSystemObject")
On Error Resume Next: .GetFolder(mPath).Delete True: On Error GoTo 0
.GetFolder(ThisWorkbook.Path).subFolders.Add "Txt"
End With
LR = Cells(Rows.Count, Range(iniCell).Column).End(xlUp).Row
For i = Range(iniCell).Row To LR Step 100
Vec = Cells(i, Range(iniCell).Column).Resize(100)
R = 1 + R
Open mPath & Format(R, "0000") & ".txt" For Output As #1
For j = 1 To 100
If Vec(j, 1) = "" Then Exit For
Print #1, Vec(j, 1)
Next
Close
Next
MsgBox "Proceso terminado en: " & Format(Timer - iniTime, "0.00 seg")
End Sub
Featured Replies
Archivado
Este tema está ahora archivado y está cerrado a más respuestas.
Hola que tal,
Tengo el siguiente código que me ayuda a exportar una columna cada 100 filas y guardar lo en una carpeta en formato .txt pero cada vez que exporto al final de la línea 100 se agrega un espacio en blanco, me pueden ayudar a quitarlo y que solo queden las 100 líneas que necesito.
Adjunto código:
Sub ExportarTXT() Dim mPath$, iniCell$, i&, LR&, Vec, j%, iniTime!, R% iniCell = "$G$2" iniTime = Timer mPath = ThisWorkbook.Path & "\Txt\" With CreateObject("Scripting.FileSystemObject") On Error Resume Next: .GetFolder(mPath).Delete True: On Error GoTo 0 .GetFolder(ThisWorkbook.Path).subFolders.Add "Txt" End With LR = Cells(Rows.Count, Range(iniCell).Column).End(xlUp).Row For i = Range(iniCell).Row To LR Step 100 Vec = Cells(i, Range(iniCell).Column).Resize(100) R = 1 + R Open mPath & Format(R, "0000") & ".txt" For Output As #1 For j = 1 To 100 If Vec(j, 1) = "" Then Exit For Print #1, Vec(j, 1) Next Close Next MsgBox "Proceso terminado en: " & Format(Timer - iniTime, "0.00 seg") End Sub