Question : deleting the last row of data programatically before importing data

I have a flat file that I is saved in excel format it has headers and a footer that I would like to get rid of before importing The headers I have the code for since they never change but the file will have different # of rows Here's what I have
Dim xlObj As Object, xlFile
Dim csvFile As String
csvFile = "C:\Ipaymetrics.csv"

xlFile = "C:\Ipaymetrics.xls"
Set xlObj = CreateObject("Excel.Application")
    xlObj.Workbooks.Open xlFile
    With xlObj
        .Range("A1:A13").Select
        .Selection.EntireRow.Delete
       
    End With
xlObj.ActiveWorkbook.SaveAs csvFile, FileFormat:=6, CreateBackup:=False
xlObj.Application.DisplayAlerts = False
xlObj.Quit
Set xlObj = Nothing


Any help will be appreciated

Answer : deleting the last row of data programatically before importing data

Dim xlObj As Object, xlFile, lastRow as long
Dim csvFile As String
csvFile = "C:\Ipaymetrics.csv"

xlFile = "C:\Ipaymetrics.xls"
Set xlObj = CreateObject("Excel.Application")
    xlObj.Workbooks.Open xlFile
    With xlObj
         lastRow=.Usedrange.rows.count
        .Range("A" & lastrow).Select
        .Selection.EntireRow.Delete
       
    End With
xlObj.ActiveWorkbook.SaveAs csvFile, FileFormat:=6, CreateBackup:=False
xlObj.Application.DisplayAlerts = False
xlObj.Quit
Set xlObj = Nothing
Random Solutions  
 
programming4us programming4us