MATLAB's xlsread gives different data than shown by Excel - hidden sheets - excel

I want to use xlsread in MATLAB R2017b to read from an externally supplied data file. Usually, this works fine for me. However, in this case I get data I can't find in the .xls file and I don't know what happened.
Here is screenshot of the .xls:
and here of the corresponding raw from xlsread:
Note that there is data in MATLAB (e.g. 'Report tem...') that cannot be found in Excel, that the columns are in a different order and that their headers also differ.
The data file is from Svenska Kraftnät, the Swedish Transmission System Operator and contains the generation and consumption of electrical energy for a certain year. You can find it here.
I use the following line to import the data in question (I am only interested in the numerical data and the timestamps, but used the raw to try to understand what is going on here):
[num,~,raw] = xlsread('n_fot2013-01-12.xls');
I am sorry if this a bad format for the question or if this is a dupe, but I didn't have a clue how to make this question more general. Please feel free to suggest improvements!

Your workbook has a hidden sheet in it, and it is that sheet that is being read.
To read the visible sheet, specify the sheet name:
[num,~,raw] = xlsread('n_fot2013-01-12.xls','Förb + prod i Sverige');
To view the the hidden sheet, on the Home tab, in the Cells group, click Format > Visibility > Hide & Unhide > Unhide Sheet. Then select the hidden sheet.
There isn't a way to tell xlsread to only read visible sheets, and by default it reads the first sheet (hidden or not).

Related

Using an Excel Macro to identify and then filter out specific rows

I've been attempting to create a macro to grab certain rows in my excel sheet to no avail. Here's what I am looking at before.
I need to find the wording "Car result printed - (Car Name)"(shown under A2) and grab the content RIGHT below it and than paste that content to another column. As the second photo shows, F-150 was properly pasted into another column. Instead of a single instance this would have hundreds obviously.
I tried using a variety of macros, but kept getting stonewalled (probably because my lack of VBA). Any help would be appreciated!
Thank you all.

Downloading File with importrange function failing - think it's a bug

I've been saving Google Sheets to Excel without any problems for a while. These sheets have always successfully saved and opened in Excel with the importrange function. However, recently it hasn't been successfully saving correctly.
It used to just have the static value (e.g, 40). There used to be an IFERROR in the first cell in the header row but now it exists in every single cell.
E.g, each cell would have something like this:
=IFERROR(__xludf.DUMMYFUNCTION(importrange(blahblah)),"40").
DUMMYFUNCTION throws an error and "40" is returned as a result. but "40" is a string, not an integer which messes up all my formulas.
I also know this isn't an Excel issue because OpenOffice is doing the same thing with the file.
I'm pretty sure this would be a bug because why would it be working for months and then suddenly stop working?
What should I do?
I'm thinking it's a bug too.
Workarounds
On Excel
Copy and paste as values only the ranges with IFERROR(__xludf.DUMMYFUNCTION(..., then use Excel's UI tools to convert numbers shown as text to numbers.
Selectively remove quotes on the IFERROR second argument of the cells causing problems
Remove =IFERROR(__xludf.DUMMYFUNCTION(),"value") except value (we could use Excel's built-in FIND & REPLACE for this)
On Google Sheets
Use Copy > Paste as values only on the range areas having formulas with non-compatible functions like IMPORTRANGE, QUERY, FILTER, etc.
If you only need the values, download it as CSV instead of XLSX
IMPORTANT
In order to help to prioritize this issue, send feedback to Google. To do this open a Google Sheets spreadsheet, click on Help > Report a problem, then fill the feedback form and submit it.
Related stuff
I posted 5 small articles about this in Spanish. You could find them listed on https://www.rubenrivera.mx/p/descargar-hcg-excel.html.
We accidentally created a workaround for this bug with a different sheet that was just set up like this.
This works when you IMPORTRANGE into another Google Sheet. We are doing it into a Google Sheet with a single worksheet - haven't tried it with multiple.
It's going to sound a little nuts but it works for us.
In the first cell of your import range put a hyperlink in the original document you are importing from. This is in the first cell of the import range. We linked it to a worksheet in the original document. It has worked and failed with an external link. With an external link it worked when I linked it to an internal link, then changed it. But when I deleted the cell and just straight linked it to an external URL it didn't work.
Then #timbo was right - put data validation in. This can be in part of the document that isn't being imported into the second sheet. I put it in the first line of the import range but outside what I was importing. It might have to be the first line. I just put a date in one cell, then in the next cell data > data validation > then choose that one date as the data range.
For aesthetics I have hidden the first row in one Google Sheet I am importing into. In another I made the first cell link the title of the sheet and put the data validation outside the import range. Both of these work.
Let me know if this works for you.
Until this bug is fixed, a workaround is to put a data validation (Data > Data Validation) on the imported data (Any kind of data validation will do).

Macro to Split Excel Data into into Existing Tabs

thanks for looking at this problem, I hope I can get some help, as I am not very experienced with VBA syntax in excel.
Background:
I will be receiving a large (1000's of lines) CSV file that will contain data entries of various lengths. Each line will begin with a code (eg, 01, 02,..., 50) and have a series of data entries following it based on that code.
So, for example
01,data,data,data
01,data,data,data
02,data,data,data,data
etc...
I need to import all of this data into an existing excel workbook that already has separate tabs and headers created to correspond with the data type.
What I believe needs to be done, is to import the csv to a new, blank sheet, then run a vba program to check the data code, and move the line to the corresponding tab. I would also like to preserve the formatting on the destination sheet.
Ultimately, what I think I need is a VBA program to read the code cell, and move the line to an existing tab based on that code, and loop through the whole column.
Most of the existing solutions I have found involve the creation of new tabs, but I wish to parse the raw data into existing tabs with headers and formatting. I am aware this may require me to manually type in the code and destination tab names in the program's logic - That will not be an issue as long as I have a base to start with!
Thanks again for your help, and let me know if I can provide any more information.

Copy varying columns to single excel sheet using a macro

I am trying to write and excel macro that will copy data from an excel file with multiple sheets. Each column will have different lengths and the name of the sheet will not always be known. I want it to start by having the user select the original file and a new one be started, which is where it will be copying to. There are multiple columns and only two of them I am interested in. They are the m/z and the intensity. I also have to know which sheet the value came from. I would prefer it if they sheet name was presented in a column next to the combined m/z's and intensity's. I am new to this and can use all the help available.
As above - use the macro recorder and make sure you are using named ranges.... an example upload would also help p[eople help you...

How to build a chart in excel, such that the source file containing data can be changed interactively?

I have a directory with many excel files with numeric data. In each file the data is arranged in the same manner (the same column names, etc...). I am interested to build an interactive
chart which will display the data according to the chosen file name.
For example, the file name will be chosen from validation list in a drop down menu fashion.
The question is how to specify the data range in the chart, such that it will change according to the name of the file that I choose.
I work with excel 2010 and don't have much experience with VBA programming :(
Thanks a lot,
Sasha
Well, a simple solution (there may be more elegant ways but that's a first hint):
Copy the data from your files in the Sheets of your workbook, you can create references (see here) or automate copies through macros (just STFW)
Create your validation list (for instance on Sheet1, cell A1). Let's assume this list contains: DataSource1, DataSource2, DataSource3.
Create Named Range for every other Sheet you have and use the same name as the one in your list (DataSource1, DataSource2, DataSource3)
In the chart source of values, use this formula: =INDIRECT(Sheet1!$A$1)
Hence, Excel will translate the source to the Named Range.
You could probably find solutions with vba too depending on your needs.
Regards,

Resources