Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27212

Last row in Microsoft.Office.Interop.Worksheet

$
0
0
In Excel Worksheets("Sheet1").Cells(Rows.count, 1).end(xlup).row will give me the last row in column "A".

What is it in VB.net?

Sub LastRow()
Dim xlApp As Microsoft.Office.Interop.Excel.Application
Dim xlBook As Microsoft.Office.Interop.Excel.Workbook
Dim xlSheet As Microsoft.Office.Interop.Excel.Worksheet
xlApp = GetObject("", "Excel.Application")
xlApp.DisplayAlerts = False
xlBook = xlApp.Workbooks.Open("C:\mypath\File1.xlsm")
xlSheet = xlBook.Worksheets("2013")
xlSheet.Activate()
With xlSheet
For k = 1 To .Cells(Rows.count, 1).end(xlup).row
'code
Next k
End With
xlApp.DisplayAlerts = True
xlBook.Close()
xlApp.UserControl = True
xlApp.Quit()
xlSheet = Nothing
xlBook = Nothing
xlApp = Nothing
End Sub

Viewing all articles
Browse latest Browse all 27212


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>