Excel dynamic data validation + named ranges + invalid typed data -- broken, or never worked? - excel

I have a dynamic list of category options I want to present in some cells using a data validation drop down. This list is ('admin') user-editable, and is located on a sheet named Config in column D. The list has a header cell in D2 and starts at cell D3, and can be as long as needed.
I wrapped the list in a named range called 'Categories', which has the formula:
=Config!$D$3:OFFSET(Config!$D$3,COUNTA(Config!$D:$D)-1,0)
The data validation cells I set to be of type 'list', and as the formula I just refer to this named range:
=Categories
The effect of this is that these cells now have a data validation drop down containing the categories. And when updating the category list, the data validation drop downs update accordingly.
However, today I found out that in Excel 2019 the drop down list behaves as usual (showing the current options), but users are now capable of typing in just about anything in those cells without Excel raising the "invalid data" prompt. This used to work just fine IIRC ever since I started using this technique (before Excel 2010), with Excel giving the users a slap on the wrists when they manually typed non-conforming data. But when I rechecked today in Excel 2019 and even in Excel 2010, it now allows invalid user-typed data without giving any prompt whatsoever.
Looking what actually got broken, I first simplified the formula in the 'Categories' named range to just refer to a fixed range (e.g. Config!D3:D11), but that didn't fix anything; the user is still able to type in anything he wants. I then replaced the formula in the data validation cells with
=indirect("Config!D3:D11")
and that makes Excel recognize invalid user-typed data again. However, by using the indirect formula I can't refer to named ranges, let alone use a formula. And indirect won't update the cell addresses when users move the list source cells around. And using these dynamic-list formulas directly in the data validation formula isn't allowed either.
So is this a genuine Excel bug, introduced somewhere in the last few years, or was this functionality always working this way and was I just not aware of it all this time?
Update
As the answer by #Ghislain said, it is blanks in the option list that causes Excel to suddenly accept anything the user types. And it appears the checkbox "Ignore blanks" controls this behavior.
I intuitively always thought the option meant something like "Allow users to keep the cell blank" or such. Not to lose my sanity, I also checked what Microsoft themselves think it does. Quote from the Excel 2019 help page for the dialog:
Select the Ignore blank checkbox if you want to ignore blank spaces.
And quote from the Excel 2010 offline chm help file:
If it’s OK for people to leave the cell empty, check the Ignore blank
box.
So it seems they themselves also haven't sorted it out quite yet :)

I believe the bug is that in your validation list you have an empty cell, which make any value authorised: I suspect D3:D11 has an empty cell. Is that really a bug?

Related

Auto populating Excel Table from keywords, error checking for defined names, etc

I am attempting to find a solution with either excel or visual basics.
I have an expanding column of remarks on multiple sheets that I need to search through for a keyword (I’m using the word “change” or “chang” to capture “changing” when needed)
When this keyword is found, I need it to give back the cell address, along with a defined name I’ve set up (one for each sheet).
I was able to make a table on a “summary sheet” to include the “new comment”, address, and defined name, and it works well enough. My only concern now is if I add a new row and therefore add a new comment in the column on one sheet, I will have to go back and add a row to my table, and make sure the address and defined name are also corresponding to that “new comment”. This will get very messy and errors can occur, especially since I could have 20+ sheets.
So far all I have been using is excel formulas. But I have also been playing around with excel macros to try and accomplish this (with no luck).
Any help would be greatly appreciated! And I of course can explain this better if need be.
Edit: I added a picture of the general basis of what I’m trying to accomplish. I can’t add the code I’ve been trying as it’s on my work laptop- so I made a simple mock-up of my sheet to include here. I took pictures of the highlighted cell in sheet 1 to show the formulas, and then a picture of sheet 2.1

Get & Transform vs Conditional Format

I am trying to use conditional formatting on the output of a Get & Transform query. (Office 365/Excel 2016 32 bit; Windows 10 Pro 64 bit).
However, when the query is refreshed, instead of the Conditional Formatting merely being extended/contracted to affect the resized column, it gets fubar'd as shown below.
I know I can obtain the desired output in a variety of ways, including VBA, and I do not need assistance in developing other methods.
Am I overlooking something either in the UI, or perhaps some method I could implement in the Advanced Editor to accomplish the normal extension of CF one would see if one just added a line to the table?
To reproduce the problem:
Base Data
Use Get & Transform to unpivot columns 2-4, and remove the Attribute column
Conditional format to hide all except the first unique entry in column A1
-->
Add another row to the original data table:
Update the query.
Note that the display and the CF "applies to" are messed up, and an extra CF condition is added
Is there anything I can do within the Query, or within Excel, to keep this from happening? Or do I have to edit the conditional formatting (vba or manual)? (Or use a different solution to develop the output).
I have tried defining the applies to range using the structured reference, or using a dynamic name range. but that did not work. The applies to gets changed to an absolute reference, and develops the same changes as noted above when the Query is refreshed.
This seems to work for me (but I literally just learned you could even do this with data by reading your post, so thank you!).
Set your conditional formatting calculation to
=COUNTIF($A$2:$A2,$A2)>1
and apply it to =$A$2:$A$4.
As an added bonus, every time I refreshed my data after updating the original table, my Applies to under the conditional formatting rule expanded the range down.

Read excel cell colour into Power BI

I have an excel file that I need to read into Power BI. Unfortunately I have no control over this file as its auto generated from another person.
Some of the cells in this file are just filled with colours and I want to be able to translate these colours when importing the data into Power BI.
For example if the colour is green in excel then show true in the corresponding power BI cell. At the moment it's just blank.
Does anyone know of a way to get cell "meta" data like colour from excel in Power BI?
Don't give up just yet...
I found an example that works in a roundabout way using Power Query in Excel. It will give you the meta data associated with each cell by its address (e.g. A1 is highlighted with color FFFFFF00). I relied on some Excel functions to associate the highlighted cell addresses with the cell values. Pulling the cell data with Power BI might take some additional work.
The technique is to use Power Query to open the Excel .xlsx file, which is basically a .zip file containing .xml documents. The color information for each cell can be extracted into a table. From there I was able to use INDIRECT() statements to read from the .xlsx workbook and extract the values from the colored cells. It worked quite well for me.
You can find a working example in the forum in the link below. The user defined DecompressFiles function in the sample uses the Binary.Decompress command to access the XML files within the .xlsx file.
https://www.excelguru.ca/forums/showthread.php?7047-Extract-Cell-Color-with-M&p=28875&viewfull=1#post28875
In my situation, I had a database export of about 7,000 rows and 50 columns into Excel. Working offline, users then went through Excel and made changes, highlighting every cell they had changed. Then they wanted me to update the database with only the highlighted cells. The background color used by each person varied but I didn't care what the color was, just that it was colored.
For each changed cell I was able to generate SQL statements to update the database and also insert into a transaction log table. The main database table was mostly flat but the few foreign key lookup values that were modified I had to update manually.
Column F uses the Indirect formula to pull data from the source workbook. Note that the source workbook must be open for the Indirect formula to read from it.
=INDIRECT("'[" & Import_Filename & "]" & Sheet_Name & "'!"&[#[SheetCellRef.2]])
Column G refines the data in Column F by putting quotes around strings or NULL if the cell is blank.
Column H grabs the column heading to know what field to update.
Column K grabs the Record ID value from the row specified in Column E.
I have had to run this process three different times for the users so my time invested paid off quickly. All I have to do is put their latest highlighted Excel file in the local folder and refresh the Power Query to generate new SQL statements.
Sorry I don't have a 'solution' posted right here. The process is still a little fragile and I'm trying to make a more robust example I can share. Stack Overflow doesn't seem to be set up for ongoing development of a solution. The point of this answer is to give hope to some of you who are desperate for a solution and won't take 'No' for an answer.
Sigh.
Color is not data. Unfortunately, many people color-code cells and then expect to be able to do things based on the color of the cell. But it's not that simple.
Although Excel now provides some ways to filter by cell color, it still cannot identify cell color with a worksheet formula.
Hence, you will need a VBA routine that evaluates all cells and records their colors in another table, which you will then need to push into your Power BI data model.
In the long run, it might be easier to talk to that other person who produces the color coded cells, and teach them a better way of doing things. Show them how to use conditional formatting based on cell values for color coding. The logic used for conditional formatting can also be applied to classify the data in Power BI.
From a data architecture point of view, the best solution is to address the problem at the source, instead of creating tools to handle bad data input.
Just sayin'.

default value to a cell of a new row without a macro (Excel)

I would like to insert a default value, to a specific cell in my worksheet,
but this default value should take care of new rows inserted in the worksheet.
I must not use a macro for this.
thanks
Maybe I am wrong, but I can not think of any way, one would be able to that. This is more a typicall database functionality. Without macros you would have to use a function or a format. A function, like values, would not be copied by inserting new rows - only formats would, so this narrows it down.
By the way, I interpreted your question to "default value on instertion of new row", not "default value when writing data in a existing clear row".
So, as a kind of "default value behaviour" you could use user defined cellformats.
i.e. use ;;'x'; as a user format and format your cell or column with it. This won't fill empty cells with 'x' but, whenever you would type in '0' it would change to 'x'.
However, I am very interested, if there is a better solution.
You can add validation to cells which can help you force a number into a particular cell, but as stated in the earlier answer a database is more designed for Default Values.
It seems to me you are trying to create a database in Excel, I wouldn't recommend this as excel is very good at prototyping algorithms however when it comes to structuring tables it can fail very quickly.
Use at least MS Access, namely as it comes with a database. Alternatives are rapid prototyping tool such as Eclipse or Netbeans, or Visual Studio if your budget can stretch that far. Couple the RAD tools with MySql (namely for ease of use and the fact that the community licence is good) and the system should be stable.

How to export SSIS to Microsoft Excel without additional software?

This question is long winded because I have been updating the question over a very long time trying to get SSIS to properly export Excel data. I managed to solve this issue, although not correctly. Aside from someone providing a correct answer, the solution listed in this question is not terrible.
The only answer I found was to create a single row named range wide enough for my columns. In the named range put sample data and hide it. SSIS appends the data and reads metadata from the single row (that is close enough for it to drop stuff in it). The data takes the format of the hidden single row. This allows headers, etc.
WOW what a pain in the butt. It will take over 450 days of exports to recover the time lost. However, I still love SSIS and will continue to use it because it is still way better than Filemaker LOL. My next attempt will be doing the same thing in the report server.
Original question notes:
If you are in Sql Server Integrations Services designer and want to export data to an Excel file starting on something other than the first line, lets say the forth line, how do you specify this?
I tried going in to the Excel Destination of the Data Flow, changed the AccessMode to OpenRowSet from Variable, then set the variable to "YPlatters$A4:I20000" This fails saying it cannot find the sheet. The sheet is called YPlatters.
I thought you could specify (Sheet$)(Starting Cell):(Ending Cell)?
Update
Apparently in Excel you can select a set of cells and name them with the name box. This allows you to select the name instead of the sheet without the $ dollar sign. Oddly enough, whatever the range you specify, it appends the data to the next row after the range. Oddly, as you add data, it increases the named selection's row count.
Another odd thing is the data takes the format of the last line of the range specified. My header rows are bold. If I specify a range that ends with the header row, the data appends to the row below, and makes all the entries bold. if you specify one row lower, it puts a blank line between the header row and the data, but the data is not bold.
Another update
No matter what I try, SSIS samples the "first row" of the file and sets the metadata according to what it finds. However, if you have sample data that has a value of zero but is formatted as the first row, it treats that column as text and inserts numeric values with a single quote in front ('123.34). I also tried headers that do not reflect the data types of the columns. I tried changing the metadata of the Excel destination, but it always changes it back when I run the project, then fails saying it will truncate data. If I tell it to ignore errors, it imports everything except that column.
Several days of several hours a piece later...
Another update
I tried every combination. A mostly working example is to create the named range starting with the column headers. Format your column headers as you want the data to look as the data takes on this format. In my example, these exist from A4 to E4, which is my defined range. SSIS appends to the row after the defined range, so defining A4 to E68 appends the rows starting at A69. You define the Connection as having the first row contains the field names. It takes on the metadata of the header row, oddly, not the second row, and it guesses at the data type, not the formatted data type of the column, i.e., headers are text, so all my metadata is text. If your headers are bold, so is all of your data.
I even tried making a sample data row without success... I don't think anyone actually uses Excel with the default MS SSIS export.
If you could define the "insert range" (A5 to E5) with no header row and format those columns (currency, not bold, etc.) without it skipping a row in Excel, this would be very helpful. From what I gather, noone uses SSIS to export Excel without a third party connection manager.
Any ideas on how to set this up properly so that data is formatted correctly, i.e., the metadata read from Excel is proper to the real data, and formatting inherits from the first row of data, not the headers in Excel?
One last update (July 17, 2009)
I got this to work very well. One thing I added to Excel was the IMEX=1 in the Excel connection string: "Excel 8.0;HDR=Yes;IMEX=1". This forces Excel (I think) to look at all rows to see what kind of data is in it. Generally, this does not drop information, say for instance if you have a zip code then about 9 rows down you have a zip+4, Excel without this blanks that field entirely without error. With IMEX=1, it recognizes that Zip is actually a character field instead of numeric.
And of course, one more update (August 27, 2009)
The IMEX=1 will succeed importing data with missing contents in the first 8 rows, but it will fail exporting data where no data exists. So, have it on your import connection string, but not your export Excel connection string.
I have to say, after so much fiddling, it works pretty well.
P.S. If you are using a x64 bit version, make sure you call the DTExec from C:\Program Files\Microsoft SQL Server\90\DTS.x86\Binn. It will load the 32 bit Excel driver and work fine.
Would it be easier to create the Excel Workbook in a script task, then just pick it up later in the flow?
The engine part of SSIS is good but the integration with Excel is awful
"Using SSIS in conjunction with Excel is like having hot tar funnelled up your iHole in a road cone"
Dr. Zim, I believe you were the one that originally brought up this question. I totally feel your pain. I love SSIS overall, but I absolutely hate the limited tools that come standard for Excel. All I want to do is Bold the Heading or Row1 record in Excel, and not bold the following records. I have not found a great way to do that; granted I am approaching this with no script tasks or custom extensions, but you would think something this simple would be a standard option. Looks like I may be forced to research and program up something fancy for a task that should be so fundamental. I've already spent a rediculous amount of time on this myself. Does anyone know if you can use Excel XML with Excel versions: 2000/XP/2003? Thanks.
This is an old thread but what about using a flat file connection and writing the data out as a formatted html document. Set the mime type in the page header to "application/excel". When you send the document as an attachment and the recipient opens the attachment, it will open a browser session but should pop Excel up over the top of it with the data formatted according to the style (CSS) specified in the page.
Can you have SSIS write the data to an Excel sheet starting at A1, then create another sheet, formatted as you like, that refers to the other sheet at A1, but displays it as A4? That is, on the "pretty" sheet, A4 would refer to A1 on the SSIS sheet.
This would allow SSIS to do what it's good for (manipulate table-based data), but allow the Excel to be formatted or manipulated however you'd like.
When excel is the destination in SSIS, or the target export type in SSRS, you do not have much control over formatting and specifying how you want the final file to be. I have written a custom excel rendering engine for SSRS once, as my client was so strict about the format of final Excel report generated. I used 'Excel xml' to get the job done inside my custom renderer. May be you can use XML output and convert it to Excel XML using XSLT.
I understand you would rather not use a script component so perhaps you could create your own custom task using the code that a script contains so that others can use this in the future. Check here for an example.
If this seems feasible the solution I used was CarlosAg Excel Xml Writer Library. With this you can create code which is similar to using the Interop library but produces excel in xml format. This avoids using the Interop object which can sometimes lead to excel processes hanging around.
Instead of using a roundabout way to do this exercise of trying to write data to particular cell(s), format the cell(s), style them which is indeed a very tedius effort considering the support SSIS has for EXCEL, we could go the "template" way to do this.
assume we need to write data in the so & so cell with all the custom formating thats done on it. Have all the formatting in a sheet, say "SheetActual", Whereas the cells that will hold the data will actually have Lookups/ refrences/ Formulaes to refer to the original data that SSIS exports in a hidden sheet say "SheetMasterHidden" of the same Excel connection. This "SheetMasterHidden" will essentially hold the master data in default format that SSIS writes data to the excel. This way you need not worry about formatting the data runtime.
Formatting the Excel is a one time work "IF" the formatting dont change very often. If the format changes and the format is decided runtime this solution maynot go very well.
The answer is in the question. Over time, it became a progress status. However, there is SSRS that will create Excel files if you create TABLE presentations. It works pretty well too.

Resources