I have a small query regarding automatic formula value calculation in excel.
In my project I will be having 200 questions and corresponding 200 answers( numerical values of 10,20 and 30). Those questions and answers are obtained from webpages and all the questions and answers are stored in my sql database. I will collect the answers that are posted in mysql database to excel with the help of mysql add-in.
My question is I have some formulas
given in my excel sheet ex:mean(C204), STDEV(C205), final risk( my own formula F209)
I want the formulas to automatically calculate the formula values whenever I import the
data from mysql. Is it possible in excel if not is there any alternative? Please help!
This is kind of a stab in the dark since I'm not at all familiar with the add in or how it operates. It seems odd that it would import data and not allow a application.calculate event to take place after import.
Perhaps... you can run the application.calculate method on worksheet change. In your VBE, double click the worksheet upon which the mysql data is dropped. Then add this code to that worksheet:
Private Sub Worksheet_Change(ByVal Target As Range)
Application.Calculate
End Sub
There's fairly good chance that the add in also snuffs events by setting application.enableEvents = false which means this won't work, but... it's worth a shot.
Related
I am trying to create a stock screener through excel. First off, Excel may not be the best choice for stock screen creation, so I'm open to alternatives, but
1. I'm almost done, and
2. I have zero programming experience
So before I tell you my problem, here's what I've got so far (Working on the ROIC tab): https://jumpshare.com/v/OxlCrsMZa18tS9bB8N1S?b=D89mk1t3hPnWdxyYxL6p
What I can't do, and what would complete the screener, is make a query for every single cell. Now I think, although I don't KNOW, that it is possible to create a macro which starts a query, tells excel where to put the data (50 rows down from the previous input), and tells excel where to find what ticker to put in (one row down from previous ticker). The query making also has to repeat to the end of the tickers. (you may be thinking: "isn't the excel row limit approx. 1 million?" It is, and my solution to that is to put half the balance sheets from columns A:F, and the other half from H:M. You don't need to include that, though, I can figure it out.)
The query pulls company balance sheets from yahoo finance, and then imports the data to the Data sheet. Since the balance sheets are all formatted the same, it is easy to sort: each metric is 50 rows down from the previous search.
The reason I need to automate this query creation process is that there are approximately 25,000 stocks, and to make a screener, I need to analyze them all at the same time; each stock, therefore, needs its own query and own data.
I've tried recording a macro, but I just can't seem to get it to repeat, offset 50 rows every new data query, and offset 1 row every new ticker.
I would really appreciate the help; I am very new to excel, and I'm not entirely sure how possible it is to do what I'm asking. Thanks!
I can't help but think you'd be better off using a database (such as Microsoft Access) instead of Excel to store this amount of data. You could still run your calculations from a spreadsheet and query the data table in the Access database. It's a fun (and maddening!) journey to develop your own Excel application. Having said that...
What you need to study in VBA is looping. Start with a simple loop on a set of the ticker values in the column:
Option Explicit
Sub test()
Dim ticker As String
Dim companyTicker As Range
Dim allTickers As Range
Dim lastRow As Long
'---sets up a range containing all your ticker strings
Dim lngMaxRow As Long
lastRow = Sheets("ROIC").Range("B" & Rows.Count).End(xlUp).Row
'---during your development, force your ticker set to be shorter
lastRow = 10
Set allTickers = Range("B5:B" & lastRow)
'---now loop through all the companies and get the info for each one
For Each companyTicker In allTickers
ticker = companyTicker.Value
'--- build up the query to Yahoo Finance using the company ticker string
' copy the data from your query to the cells in your workbook
Debug.Print "ticker is " & ticker 'use a debug.print to check as you write the code
Next companyTicker 'get the next company ticker
End Sub
I have a large amount of data that reference cells. I want to lock these references without going into each cell to change the equation. I know there is a way to do a script in excel. I don't know if there is a way to create the same type of script in excel.
Those interested in the excel script:
Sub test()
Dim c As Range
For Each c In Selection
c.Formula = Application.ConvertFormula(c.Formula, xlA1, , xlAbsolute)
Next
End Sub
Thanks Guys!!
There is no Spreadsheet Service method that is equivalent to VBA's Application.ConvertFormula().
You could enter a feature request on the Google Apps Script Issue Tracker. If you do, add a comment here to let us know the issue number.
I'm a VBA newbie, but have successfully created a handful of useful Excel Functions. The one I'm working on right now, which seems like it should be simple, is eluding me. I think I'm misunderstanding the syntax, and need some guidance.
Consider the following screen capture; I am attempting to create the function in Column E, which is simply the VALUE from D$n.
So far, this is as far as I've gotten:
Function PASTVALUE(q As String)
q.PasteSpecial Paste:=xlPasteValues
End Function
which, if I understand properly, is reading the input value (in my case, the contents of cell D$n) as a String, then pasting it using PasteValues.
Do I need to somehow copy it before I paste it? I thought that the q As String parameter was what brought it into the function.
But then if I'm not copying, is it trying to paste from an empty clipboard...in which case I have no idea what I should be using to accomplish this.
Help!
You can just ''transfer'' the value(displayed) over like this
Function PASTEVALUE(rng As Range)
PASTEVALUE = rng.Text
End Function
or use the Evaluate() function to evaluate the formula in that range
Function PASTEVALUE(rng As Range)
PASTEVALUE = [rng]
End Function
There are some features of Excel's object model that you cannot access during a calculation; i.e. during the evaluation of a function. Broadly speaking they are the ones that manipulate the value in cells in some way. If the converse were true, then the calculation process in Excel would break.
Pasting clipboard data into the worksheet falls therefore into the forbidden category.
One solution would be to put your code in a macro; accessible by a button on the worksheet. That is outside the calculation cycle and therefore permissible.
I wanted to check in here to see if anyone has any suggestions before submitting a bug report to Oracle.
I'm using MySQL for Excel in Excel 2013, and when trying to import a table that has a TIME type column, the import fails and I get the following error message:
An error occurred when trying to import the data.
Method's type signature is not Interop compatible.
I looked up information about Method's type signature is not Interop compatible. but found only things relating to C/C#.
I'm trying to insert data that is formatted as a relative time duration, e.g. 00:02:34 (2 minutes 34 seconds), but I cannot find a way to do this. MySQL for Excel won't import a TIME column, and when I define the column as VARCHAR, it does some calculation on each value when it's submitted to the database; 00:02:34 ends up as 0.00178240740740741 in the database.
Is there a different column type that I can use that will leave a string like 00:00:00 unformatted?
That's because excel can't handle the conversion of that data type so what is being reported... the .001782... is the time in days. So if you take 24*60*60* that number you get your 2:34...
When importing to Excel you can append a single quote ' to the beginning of the string value. This kept the formatting in the cell; but it may cause problems with the data later when you have to pull the ' off for processing.
This issue in MySQL for Excel was fixed [at least partially] since version 1.3.0, when you choose to a Create Excel Table on the Advanced Options menu of the Import Dialog. (If you leave that option unchecked the error still appears.)
A bug report with a similar description of the error message you describe has been raised to the MySQL team in charge of MySQL for Excel. If you wanna receive updates on this please feel free to suscribe to Email Updates in this link: http://bugs.mysql.com/bug.php?id=72504
The 1,500 page Access 97 Bible (don't laugh!) that I've been given by my boss to solve his problem doesn't solve my problem of how to solve his problem, because it has nee VBA code.
Let me first make clear that I've made attempts to solve this without (much) coding, and that I've coded quite a bit in VBA already, so I'm basically familiar with most things including recordsets, queries, etc etc but have problems with MS Access limits on how to form a report with data coming from VBA variables. I'm also versatile in most programming languages, but this is not a language problem but rather a "how to/what's possible" problem.
My problem right now is that dragging the query fields into the Detail subform and putting them into cells in columns setting Left and Top with VBA code are moving them alright, but each cell is on a new page. Unfortunately, there is multiple data in each cell that won't conform to the Create Report Guide options available.
So my question is simply this: Can someone point me to working examples of code that create, place, and fill with VBA variable strings, text fields at any coordinate I please on a paper size of my choice?
Edit: The above is not an option, as I understand this will prohibit the client from getting an .mde database. What remains, then, is to merely ask for some sound advice on how to get several rows GROUPed BY weekday and machine (see below) into a recordset or similar for each cell. I guess the best way is to count the number of columns in the table (machines in the sql result) and create 5 rows of these with dummy data, then go through the result rows and place the data in the relevant controls. But if you have ideas for doing this work better and faster, write them as answers.
Sorry for this, I knew there was something I wasn't understanding. Basically, I thought Access supported creating reports dynamically via VBA, ie. "generating pages with data" rather than "preparing a flow of controls connected to datasources". But Access requires that you create an ample amount of dummy, unlinked controls manually, then either fill or hide them and that's how they become "dynamic".
This is for Access 2003 on a remote server accessing local and remote ODBC SQL database tables, if relevant. The goal is to make a week schedule of n columns (n=number of machines at a certain plant) x 5 rows (weekday Mon-Fri), and put 1 or more recordset rows (=scheduled activities for that day on that machine) in each of the "n by 5 table" cells.
If you detect venting frustration in this post I can only ask your forgiveness and hope for your understanding.
So, has many techniques for this:
Ex: 1) using dinamic sql for this:
'Create a function to make sql query
Function MakeMySQlReport(Parameters):
Dim strSql as string
Dim strMyVar as string
strsql = vbnullstring
strsql = "Select " & myVar1 & " as MyFieldVar1, * from myTable where Fieldx =" & Parameters
MyReport.recordSource = ssql
End Function
Ex: 2) create function that returns yours strings:
Function MyString1() as string
MyString1 = 'ABC'
end Function
An in your report, select the textbox will receive the value and type =MyString1()]
I hope this help to you, need more examples?
Solution:
Create many objects manually (grr!)
name them systematically
put them in a Control Array (get all Me.Controls, sift out the ones you're interested in, and put them in an indexed array)
go through the array and change their properties