Excel SQL Table Formula's clearing - sql

Apologies if asked elsewhere, having checked couldn't find anything. I've got a SQL driven table in Excel. When my table refreshes, resulting in no data, it completely clears out a series of none-SQL driven columns on the far right of the table. Is there any way at all I can force Excel to store the formula on the cell, regardless of whether the row has cleared?

To ellaborate on my comment:
Below shows a simple query returning 10 dates from a database. The right column is a simple formula in excel adding 10 to the date:
If I update the query to return the top 0, you find the formula disappears because there are no values to assign the formula to:
But, I then update the query to bring back the original 10 dates again, and hey-presto, the formula re-appears!:
So I wouldn't think that you need to worry that it has gone. I would expect that they would come back once you return some values from your query.
FYI - More help on calculated columns can be found here from Microsoft support.

Thanks! I think I had 'preserve column sort/filter/layout' unticked - which was causing the formula to be lost when the data refreshed! Schoolboy error, thanks again

Related

Excel Table Formatting Does Not Re-Apply After Refreshing Data From SQL Server

How would I force cell formatting to take effect automatically after a data refresh?
I have a connection set up to pull data from SQL Server to a table in Excel.
However, upon initial pull and refresh - cell formatting does not take effect on these cells, until I interact with them in some way such as double-clicking, or pressing F2, or even using Text To Columns to fix them all at once.
My settings indicate to preserve cell formatting, and it is preserved, it just doesn't seem to apply until interaction of some kind occurs.
See here before and after shots:
The issue is affecting formatting of my entire table, the specific column shown IS a date type in SQL Server.
Is there something I'm completely overlooking to have cell formatting apply to cells after data refresh, or if this is just a bug in Excel, would it be possible to maybe macro out a Text To Columns action after every data refresh?
I'm on Excel 2013, with SQL Server 2008 R2.
Any help appreciated,
Thanks.
EDIT 1: No formulas exist in table, has been tested on multiple machines and on Excel 2013 and 2016 and issue still occurs.
I think this is an issue of Excel not recognizing your data as a date. Try this cast for your date from SQL:
CAST(YourDate AS smalldatetime) "Date"

extract data in exel sheet using macro

you most probably going to think "what an idiot" but remember i never done any type of coding before so this is all new to me,
My problem are that i'm working on a HUGE excel sheet with loads of data that is not needed. i need to sort the data into a few columns, i only need column "A,K,AN,AQ" but in column "AS" i only need certain values (yes,no,blank) i only want the yes and blank values. like i said never done any coding before but i know that you can use an macro to do it so please help, how do i go about this?
before trying to get into macros, try to use functions with if else statements. They are quite easy to handle. Like: If (yes) then put it into X. Later, you could select all needed. Also, check the, how the dollar sign is used
use this links to see, if it is something for you.
One quick and dirty way of getting this job done would be to:
Delete the columns you don't need.
Select all cells in the range you're interested in, click the Insert menu, and choose "Table". If your columns have titles, select the box for "My Table has Headers."
-This turns your data into an array so that Excel recognizes that each row is an entry (instead of thinking that the cells are unrelated).
Now you can use the filter icon in the column headers to select and display only the rows containing the values in column X that you're interested in.
Note that there are some limitations to what the table feature is good for, so, as always, whether this is a good solution for you depends on what you want to do with the data.

Excel pivot table - wrong number ordering

I have an issue with number ordering in pivot tables. I tried almost everything... Observe:
As you can see somehow the pivot table sorts the days in a wrong order. In the data source all day values are numbers formatted as General - NOT DATES! Week numbers are number as well, again formatted as general.
Another interesting point is that a different pivot report which is using data from this file has the same issue. Note that the data is processed during the export and is converted to date using VBA DateValue function etc.
We use this report about a year now and we never had this issue before. Rebuilding the pivot table fixed the issue but in this report I have about 10 pivot tables and charts linked to VBA code, slicers, named cells etc. Rebuilding the whole file would take days.
First I´ve added a picture but my karma or whatever wasn´t good or something :)
Anyway, thank you for your comments, I´ve already figured it out so here is my answer:
I´ve just selected the row which I wanted to sort and sorted it with the basic excel sorting tool in the Home tab. So stupid...
Sorry for bothering with such a stupid question... :)

Deleting data in last cell of data in Column A

I am in need of assistance agian. When my macro works, the number 1 is populated in the final cell in column A because the coding is set up to place a number 1 or 2 depending on other data until the last row of data. Since the last row of data has necessary information in other columns, I wanted to delete the 1 in column A because it is not needed. How do I code to take away the value in the final cell of a column? I've tried referencing to it and if statements. I am sure I am missing something simple.
This is my first macro using VBA.
Thanks.
I just started working with VBA in the last day or two, but I believe the thing you are looking for is: Cells(x,y).End(xldown).ClearContents
Alternatively, I think Range("A1").End(xldown).ClearContents would be equally effective.
But I just started doing this myself, so take with spoonful of salt.

SQL query in excel returning one value uses two rows or columns?

I'm running a query from excel to sql server that returns a single value. It seems as if this uses two cells in excel. Is this correct? Is there a way to prevent this? Is there a way to predict whether excel will use an extra row or an extra column (I've seen both happening)?
If, in excel, I use "import external data -> new database query", and then do a count() on an sql server table, excel usually puts the result in the cell underneath the cell which I had selected when starting to do the new query (not adding an extra row, but putting the value there). Sometimes, it will instead insert an extra column before the column of the cell I had selected and put the result in the new column in the same row as the cell I had selected.
Is there a way to have excel return the value in the same cell as the one selected when starting the query? If not, is there a way to predict which of the two scenarios above will happen?
Thanks,
Ernst
I finally found the answer:
uncheck preserve column sort/filter/layout