Para Dante - Importar Txt a un rango de la hoja de excel

Estimado Dante:

Tengo un archivo TXT delimitado por pipe con nombre "Listadecliente" guardado en la siguiente ruta D:Ventas\Clientes\ventas. Necesito importarlo a una hoja de excel, más exactamente a la hoja clientes en el rango b5:k26900 o de b5:(ultima firma con datos).

Encontré algunas macros pero me habren el asistente y no quiero usar el asistente.

Agradezco tu valisisima ayuda.

Gracias.

1 respuesta

Respuesta
1

Enviame tu archivo txt y el de excel, recuerda poner en el asunto tu nombre y la pregunta.

Te envíe el archivo

Gracias

Esta es la macro para importar un txt

Sub ImportarTxt()
'Por.Dante Amor
    Application.ScreenUpdating = False
    Set l1 = ThisWorkbook
    Set h1 = l1.Sheets("clientes")
    u = h1.Range("B" & Rows.Count).End(xlUp).Row
    If u < 4 Then u = 4
    h1.Range("B4:L" & u).ClearContents
    ruta = l1.Path & "\"
    nombre = h1.[B2] & ".txt"
    '
    Workbooks.OpenText _
        Filename:=ruta & nombre, Origin:=xlMSDOS, _
        StartRow:=1, DataType:=xlDelimited, _
        TextQualifier:=xlDoubleQuote, _
        ConsecutiveDelimiter:=False, _
        Tab:=False, Semicolon:=False, _
        Comma:=False, Space:=False, _
        Other:=True, OtherChar:="|", _
        FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1), _
            Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), _
            Array(8, 1), Array(9, 1), Array(10, 1)), _
            TrailingMinusNumbers:=True
    '
    Set l2 = ActiveWorkbook
    Set h2 = l2.ActiveSheet
    h2.Columns("J").NumberFormat = "m/d/yyyy"
    u = h2.Range("A" & Rows.Count).End(xlUp).Row
    h2.Range("A1:J" & u).Copy h1.Range("C5")
    l2.Close False
    Application.ScreenUpdating = True
    MsgBox "Importación terminada", vbInformation
End Sub

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas