How can I import Excel cell reference or formula store in SQL table? - sql

I have the following SQL table.
I imported this table into Excel sheet by following
Data-->Get Data-->Database-->Import from SQL database
On the Excel sheet, I have income calculated in cell J1.
I want to give reference of cell J1 in my SQL table which I have done above.
Excel output is
In cell C2 cell reference/formula is importing from SQL table and in cell C4 it is written directly.
It is not working in cell C2 but the same formula is working on cell C4.
How can I bring cell reference or formula from the SQL table?

There is a quick way to do evaluate the formula in Excel after refreshing the data from the SQL server.
Replace = with = in Excel. It's the same character but it evaluates the formula.
I found this interesting answer in another SO answer post. You can also create a macro and run it every time after refreshing the data as described in another answer in the same link.

Related

Keep cell format when referring to a date cell in an Excel formula

I'm trying to generate SQL queries based on data from an Excel sheet.
So I did write this formula
="INSERT INTO "&$B$1&" VALUES('"&Personnel!A1&"','"&Personnel!B1&"','"&Personnel!C1&"','"&Personnel!D1&"','"&Personnel!E1&"','"&Personnel!F1&"','"&Personnel!G1&"','"&Personnel!H1&"','"&Personnel!I1&"','"&Personnel!J1&"','"&Personnel!K1&"','"&Personnel!L1&"','"&Personnel!N1&"','"&Personnel!O1&"','"&Personnel!Q1&"','"&Personnel!R1&"','"&Personnel!S1&"')"
Which almost works except the fact that datas from Date Cells on my "Personnel" sheet gives me things like 24136 when I'm expecting 29-01-1966. How can i fix this and keep the original format ?
You can modify your query to change those values to their text equivalent using the TEXT function e.g.
="INSERT INTO "&$B$1&" VALUES('"&TEXT(Personnel!A1, "yyyy-mm-dd")&"'"

Excel Formula to VBA code Conversion

I am trying to create a macro that allows me to scan columns and rows of data and insert a formula into the blank cells. I am able to complete this task with the following excel formula:
=IF(ISBLANK(W4),((IFERROR(DATEDIF(MAX($P4,DATE(2016,5,1)),MIN($Q4,DATE(2016,8,1)),"d"),0)/(DATEDIF(P4,Q4,"d")))*$T4),W4)
My question is, is there a way I can put this into vba code so that I can run a macro that will automatically apply this formula in a column of my excel sheet across 30 rows? Therefore, the next row would read:
=IF(ISBLANK(W5),((IFERROR(DATEDIF(MAX($P5,DATE(2016,5,1)),MIN($Q5,DATE(2016,8,1)),"d"),0)/(DATEDIF(P5,Q5,"d")))*$T5),W5)
Thanks in advance for the help!
You can use
Range("RangeToCopyFormulaTo").Formula = Range("CellToCopyFormulaFrom").Formula
Excel will take care of updating the cell references, same as when you copy/paste

using SQL query to populate Excel cell

How can I have a cell populated by a sql query?
For example, if a user manually input a part number into cell A1, cell A2 would populate by completing a query using A1 as a parameter.
Something like:
=select table.desc from table where table.partNo = 'A1'
Hope this makes sense.
Depends whether you want to populate cell by cell or by range.
I have used EPPlus along with C# to populate excel templates.
In our case the values are stored in database after the rule evaluation for each cell and then its either gets displayed on screen or exported to excel.
Its not a few lines of code which I can paste it here but you can try below:
1. Define rules with the sql criteria and definition that defines the coordinates of cell
2. Evaluate rules and persist the values
3. Display the values
Ping me if you need more help on this

Change an excel function into vba code

I have written 2 Excel functions to copy data to cell G12 when data is entered in cell F12
=IF(ISBLANK(F12)," ",(F12))
if data in the deleted from cell G12 it is copied to H12
=IF(ISBLANK(G12),(F12)," ")
these work perfectly but I was wondering if the same procedure can be carried out in vba on a dynamic range as I want to keep adding rows
To achieve your requirements, you can format your range as a table from Home>Format as Table. Now, assuming your table as two columns respectively named "name" and "non blank name", you can enter the following formula in the second cell of the second column:
=IF(ISBLANK([#Name])," ",[#Name])
As you add rows to the table, the formula will be copied automatically to the new row.

Spliting cells in excel based on some parameter

I wanted to know who can the following content be split in to two cells:
if i have C:\Pgm\Win\a1.c
in one cell
how can i split it in to two cells
C:\Pgm\Win a1.c
In my excel I have around 500 such rows.Is their any key availabe to do. I am using excel 2007.
You can use formulas to do the split
Assuming first string is in cell A1, place these formulas
Cell B1
=LEFT(A1,FIND("*",SUBSTITUTE(A1,"\","*",LEN(A1)-LEN(SUBSTITUTE(A1,"\",""))))-1)
Cell C1
=RIGHT(A1,LEN(A1)-FIND("*",SUBSTITUTE(A1,"\","*",LEN(A1)-LEN(SUBSTITUTE(A1,"\","")))))
Copy down for all data rows
Once these formulas are calculated, you can copy/paste values and delete the original data if required
by using data to columns ....we can get...in to multiple columns...but it will not be an 100% solution