TXT a XLS a distintas hojas y posición inicial

Hola:
Necesito una pequeña ayuda para terminar lo siguiente.
Estoy haciendo una macro que exporta a Excel datos de un TXT...
El primer string del TXT tiene el nombre de la hoja, a la cual se debe insertar ESA fila. Esto funciona  bien.
Lo que no logro es hacer que CADA Hoja tenga una posición inicial distinta , fila y columna distinta.
Cabe destacar que en el método Llenar() hice un Contador de Filas para lograr que siempre me insertara a partir de una fila determinada en cada hoja. Pero, ahora requiero todo lo contrario.
En el método LlenaLinea() está el string con el  nombre de cada hoja y la matriz con los datos.
_
datostab.txt:
GENERAL LENG    2    NULL    1    3    HORACIO    2    8    31
GENERAL LENG    2    2010    1    3    11.6    2    8    4.5
GENERAL LENG    2    2010    1    3    11.7    CLAUDIO    8    33
Prioritarios GENERAL LENG    23    23.5    43.6    5.5    23.5    2.5    11.5    1
Prioritarios GENERAL LENG    7.5     11    1.5    2.5    12.5    23.4    3.5    2.4
____
Macro:
Dim sUltimaHoja As String
Dim CntFilas As Integer
Sub Llenar()
    Set fso = CreateObject("Scripting.FileSystemObject")
    Dim sRuta As String
    Dim sLinea As String
    Dim sHoja() As String
    sRuta = ActiveWorkbook.Path
    Set archivo = fso.OpenTextFile(sRuta + "/datostab.txt", 1)
    Do While Not archivo.AtEndOfStream
        sLinea = archivo.readline()
        sHoja = Split(sLinea, vbTab)
        If UCase(sUltimaHoja) <> UCase(sHoja(0)) Then
            If Trim(sUltimaHoja) <> "" Then
                'For i = 1 To 8
                    'Suma CntFilas + 1, i, 2
                'Next
            End If
            sUltimaHoja = sHoja(0)
        '    CntFilas = 4
        Else
         '   CntFilas = CntFilas + 1
        End If
        If Not SheetExist(sUltimaHoja) Then
            Sheets.Add
            ActiveSheet.Name = sUltimaHoja
        End If
        LlenaLinea sUltimaHoja, sLinea, CntFilas
        'LlenaLinea sUltimaHoja, sLinea
    Loop
    'Para la última hoja
    'For i = 1 To 8
        'Suma CntFilas + 1, i, 2
    'Next
    archivo.Close
    MsgBox "Importado"
End Sub
Sub LlenaLinea(ByVal sHoja As String, ByVal sLinea As String, ByVal nFila As Double)
'Sub LlenaLinea(ByVal sHoja As String, ByVal sLinea As String)
    Dim columna As Double, fila As Double
 '   columna = 1
    Sheets(sHoja).Select
    If sHoja = "GENERAL LENG" Then
    columna = 5
    fila = 9
    End If
    If sHoja = "Prioritarios GENERAL LENG" Then
    columna = 7
   fila = 6
    End If
    b = Split(sLinea, vbTab)
    For i = 1 To UBound(b)
        If (IsNumeric(b(i))) Then
        Dim totColumna As Integer
        totColumna = columna + i
        Range(Cells(fila, columna), Cells(nFila, totColumna)) = CDbl(b(i))
       ' Cells(nFila, columna + i) = CDbl(b(i))
        Cells(nFila, columna + i).Interior.ColorIndex = 6
        Else
        Range(Cells(fila, columna), Cells(nFila, totColumna)) = b(i)
        'Cells(nFila, columna + i) = b(i)
        Cells(nFila, columna + i).Interior.ColorIndex = 6
        End If
        'If (IsNumeric(b(i))) Then
        'Cells(nFila, columna + i) = CDbl(b(i))
        'Cells(nFila, columna + i).Interior.ColorIndex = 6
        'Else
        'Cells(nFila, columna + i) = b(i)
        'Cells(nFila, columna + i).Interior.ColorIndex = 6
        'End If
      'Para diseñar celdas
        Dim vaColumna As Integer
        vaColumna = columna + i
    Range(Cells(nFila, vaColumna), Cells(nFila, vaColumna)).Select
    Selection.Borders(xlDiagonalDown).LineStyle = xlNone
    Selection.Borders(xlDiagonalUp).LineStyle = xlNone
    With Selection.Borders(xlEdgeLeft)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeTop)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End With
    With Selection.Borders(xlEdgeBottom)
        .LineStyle = xlContinuous
        .Weight = xlThin
        .ColorIndex = xlAutomatic
    End...

1 respuesta

Respuesta
mmm... ¿A qué te refieres con "todo lo contrario"?
¿Qué es lo que deberia resultar al final?
Echo a correr tu macro.
Tengo que descomentar estas dos filas para que no marque error
'    CntFilas = 4
'   CntFilas = CntFilas + 1
En Rango E4:M9 en GENERAL LENG
31 31 31 31 31 31 31 31 31
45 45 45 45 45 45 45 45 45
33 33 33 33 33 33 33 33 33
33 33 33 33 33 33 33 33 33
33 33 33 33 33 33 33 33 33
33 33 33 33 33 33 33 33 33
En Rango G4:O6 en Prioritarios GENERAL LENG
   1      1      1      1      1      1      1      1      1
24 24 24 24 24 24 24 24 24
24 24 24 24 24 24 24 24 24

Añade tu respuesta

Haz clic para o

Más respuestas relacionadas