How can I use xltoRight, xlDown and similar utilities from MATLAB?

9 views (last 30 days)

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 27 Jun 2009
The following example uses the Excel functions xltoRight and xlDown to select a contiguous block of data. For more information on how these functions work, consult your Microsoft documentation.
Note that there must be a block of data around the specified cell B9; otherwise, these Excel functions will select the entire worksheet, as detailed in the Microsoft documentation.
e = actxserver ('Excel.Application') % open Activex server
eWorkbooks = e.Workbooks
exlFile = eWorkbooks.Open('C:\MyFile.xls')%open file
exlSheet1 = exlFile.Sheets.Item('Tabelle1')%Choose Sheet
lastCol = exlSheet1.Range('B9').End('xltoRight').Column % find last column
% Convert column number to Excel column code
if (lastCol <= 26)
lastColchar=char(96+lastCol)
else
lastColchar = [char(96+floor((lastCol-1)/26)) char(97+rem(lastCol-1,26))]
end
lastrow = exlSheet1.Range('B9').End('xldown').Row % find last row
myrange=[lastColchar num2str(lastrow)]
data_ran=['b9:' myrange]
data=exlSheet1.Range(data_ran).Value% These are the requested data

More Answers (0)

Products


Release

R2006b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!