copy data from a csv to an excel using vba

3

I want to copy data that I have in a csv to an excel using vba. I have the code that does it, but I do not want to copy the first row of the csv and I do not know how to do it. This is my csv:

And this is my vba code of an excel:

Private Sub Workbook_Open()
'
' Makro1 Makro
' Makro indspillet 17-04-2017 by Cristina
'

'
Dim valuesLine
    FilePath = "C:\Users\Tmicro2\Desktop\DATOS.csv"
    Open FilePath For Input As #1
    myColumn = 1
    myRow = 2
    Do While Not EOF(1)
        Line Input #1, valuesLine
        myarray = Split(valuesLine, ",")
        For i = 0 To UBound(myarray) - LBound(myarray)
            Hoja1.Cells(myRow, myColumn) = myarray(i)
            myColumn = myColumn + 1
        Next i
        myRow = myRow + 1
        myColumn = 1
    Loop
    Close #1
End Sub

This is the result I get:

What should I modify the code so that I do not copy the titles of Registration, Group, Subject ...?

    
asked by Cristina 24.04.2017 в 10:25
source

1 answer

2

I would make a variable that indicates in which row of the csv you are, and if you are in the first one, skip it:

myColumn = 1
myRow = 2
filaCSV = 1 ' Variable indicando el numero de fila que estamos procesando del CSV
Do While Not EOF(1)
    Line Input #1, valuesLine
    if(filaCSV <> 1) then 'Si no es la primera linea, hacemos el proceso 
        myarray = Split(valuesLine, ",")
        For i = 0 To UBound(myarray) - LBound(myarray)
            Hoja1.Cells(myRow, myColumn) = myarray(i)
            myColumn = myColumn + 1
        Next i
        myRow = myRow + 1
        myColumn = 1
    end if
    filaCSV = filaCSV +1 'Sumamos 1 al numero de fila actual del CSV
Loop
    
answered by 24.04.2017 / 10:29
source