From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

DIAdem

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the last row in an excel file

Hey,

 

do anyone know how i can get the last row in an Excel file? 

 

I have wrote this but it doesnt work..

 

Dim str_SL, objExcel
Dim objWorkbook


str_SL = "C:\Root\Eve.xlsx"
Set objExcel = CreateObject("Excel.Application")
Set objWorkbook = objExcel.Workbooks.Open(str_SL)
objExcel.Visible = false

MsgBox objExcel.Cells(Rows.Count, 2).End(xlUp).Row

0 Kudos
Message 1 of 2
(2,107 Views)

Hi Dia_Nutzer,

 

Are you wanting to load data channels from an Excel file?  In that case I'd recommend creating a new DataPlugin that uses the "Spreadsheet Reader".  It has a built-in "Sheet.MaxPosition.Row" ability.  DIAdem 2019 also has a new Excel file reader object that I'd recommend for reading out or writing to selected cells of an Excel file, if you're DIAdem version isn't earlier than 2019.

 

If you're stuck with ActiveX, this is a function I used way back when I had to lean on the Excel ActiveX object inside DataPlugins. 

Function GetRangeArray(Sheet, StartLetter, StartRow, ColNumber)
  Dim iMax, Range, RangeArray
  Const xldown = -4121
  On Error Resume Next
  Set Range = Sheet.Range(StartLetter & StartRow)
  Set Range = Range.Offset(0, 0)
  Set Range = Range.Resize(1, ColNumber)
  iMax = Range.End(xldown).Row
  Set Range = Range.Resize(iMax-StartRow+1, ColNumber)
  RangeArray = Range.Value
  IF Err.Number <> 0 THEN ReDim RangeArray(1, ColNumber)
  On Error Goto 0
GetRangeArray = RangeArray
End Function ' GetRangeArray()


Brad Turpin

DIAdem Product Support Engineer

National Instruments

Message 2 of 2
(2,048 Views)