0
votes

In MATLAB I am using ActiveX to import many columns of data from an excel file. Each column is of a different and unknown length. Therefore I do not know what cell range to put.

Range = get(hSheet5, 'Range', '??:??');

Is there a way for matlab to detect the length of the column so that I can then know what cell range to put when importing it?

1
I don't know what about Matlab and ActiveX, but in any form of integration with Excel there is a way to do this. In your worksheet object all you need to do is something like: aWorksheetObject.UsedRange.Columns.Count (or Rows). Not sure hoe relevant this is, so hope it helps. - Aleksander Lidtke
Also this: stackoverflow.com/questions/3244863/… might be useful to get the length of a particular column (it appears not to have an ActiveRange property, at least in python). - Aleksander Lidtke
@AleksanderLidtke Yes, that is working. However, it gives me the number of rows of the largest column on the worksheet. Is there a way to modify it so that it gives me the number of rows of any column I want? - ben
Have you looked at this post which suggests using something like Range("A1").End(xlDown).Row (or any top cell of an arbitrary column)? Does that work? - Aleksander Lidtke
@AleksanderLidtke Oops! What I meant to say is that yes, your suggestion (or rather the ones on the page you linked to) worked out the best. The solution I used was lastcol=hSheet6.Range(irange).End('xltoRight').Column (So I deleted my earlier comment). Go ahead and put it as answer if you want. - ben

1 Answers

0
votes

I wonder if the solution should use ActiveX. I would do it with built-in function to read XLS file:

columnB = xlsread(fileName, sheetName, 'B:B');