How to copy and paste a single row in an excel file to another excel file?

5 views (last 30 days)
Hello,
I am trying to copy a single row from multiple excel files and paste them into a master document. These files are all in one folder, but do not have similar file names. The row I am looking to copy contains both numbers and letters, and is row 3 of the original excel sheet.
Here is an example of how the excel file is formated
A B C D E F ...
1 L L L L L L
2 R R R R R R
3 13 Q 14 T S 75
4 0 0 0 0 0 0
Any help is much appreciated!

Accepted Answer

GT
GT on 3 Dec 2018
I am using R2018b, and there are a couple of ways of solving this. I like the following:
ds = spreadsheetDatastore(pwd,'Range','A3:D3','ReadVariableNames',false)
ds.readall
Please note that:
  • Range is where we specify the range that you are looking for in Excel (same way you would declare this in Excel)
  • Given that I don't know the VariableNames I put false, but you could extend this
  • I used pwd as the path but you could run this from anywhere:)
I hope this helps:)
There are other types of Datastores which make these kind of things really simple. I believe SpreadsheetDataStore came out in R2016a.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!