So I am running a spreadsheet with a whole bunch of stock codes.
I don't have any problem going via the IRESS addin for excel to get a data feed of prices.
However in my sheet, it gives the option for client to stocks and then it pre-populates a table with information such as stock code, price. However it also is meant to do a calculation of how many units a person would have if they were to invest $x amount into each stock. The problem here is when I run a macro, the iress feed does not refresh and just shows #Value in the cell.
However when I end the macro, the prices start feeding.
This is what I get:
The macro breaks when I try to calculate the units.
For formula that the code enters into the cell is:
Cells(i, cp.Column) = "=IRESSRtd( ""Quote"" , ""13"" , ""0"" , "" " & Cells(i, stock.Column) & """)/100"
'i' is a loop starting at the first row where there is a stock code, to the lastrow where there is a stock code, then under the "current price" column, it enters that formula.
cp.column is the column reference for 'cp' where 'cp' is set by a .find function.
Same with the stock.column reference.
Might be a bit of a long shot, but does anyone know how I can get the Iress feed to update without having to stop my macro?
IRESS support recommends to either use the UI of the Excel addin to generate the RTD links, or if you really want to do a lot more number crunching in the VBA you could call the IRESS API directly - i.e. IRESS Server API COM interface calling the PricingQuoteGet method (with Updates enabled). There is a sample on getting quote info back in the IRESS help files ”IRESS PRO FE > Help | API Documentation | IRESS Server API | Programmer's Guide
Related
I am making a macro which extracts information from SAP based on account and period. I have recorded it with the SAPGUI and it works fine with different variables (my goal is to have the same macro for different excel files based on a template). Where my problem comes from is when the number of accounts is changed, due to the fact that the set focus number is changing.
session.findById("wnd[0]/usr/lbl[70,13]").SetFocus
session.findById("wnd[0]/usr/lbl[70,13]").caretPosition = 8
Can someone tell me if its possible to make the number "13" in the brackets a variable and maybe how (the number is equal to count of the accounts + 12 and I have the number I need in a specific cell)
Regards,
Ivan
I would answer the first question Can someone tell me if its possible to make the number "13" in the brackets a variable like that
Dim pos as long
pos = 13
session.findById("wnd[0]/usr/lbl[70," & CStr(pos) & "]").SetFocus
I have a dynamic query in a sheet that uses a parameter in cell C1. So, In column A there are codes, and in column B are those code descriptions and based on the value in cell C1, the query will refresh to display codes related to the value in C1. When the value in C1 changes, I get a "Run-Time Error 1004: MS Excel is refreshing some data. Please try again later", every time. When I select "End" it goes away and refreshes the query successfully, after a couple seconds, Does anyone know the reason behind this? Can I get rid of it?
There is a search feature. when the user clicks "Search" to search for the codes they're looking for, the search button is assigned a macro that essentially just navigates to the sheet which displays the codes. However, in that macro, I added this bit of code:
Sheets("department_lookup").Cells(1, 3).Value = Sheets("lookup").Cells(2, 2).Value
With Sheets("department_lookup") .Range(.Cells(1, 1), .Cells(LR, LC)).AutoFilter field:=3, Criteria1:=.Cells(1, 3).Value, VisibleDropDown:=True End With
I found this occurs when you are using a combination of Excel native queries and VBA DB code. For me, I found I couldn't access the database using an OLEDBConnection when Excel was refreshing using it's native refresh function.
SOLUTION:
I had to turn BackgroundQuery = False on the native queries.
(This can be done from the Query properties using the GUI)
EXPLANATION:
BackgroundQuery allows you to use the spreadsheet while it is refreshing data. This is okay for a user who wants to use a spreadsheet but not for a VBA macro that wants to talk to that same database. When set to false it causes Excel to hang during a refresh. This stops your operations from colliding.
If this isn't your exact scenario look for similar collisions where 2 queries are stepping upon eachother.
For people like me who knows a little bit about ODBC, from Excel, go to Data tab. Click on Queries & Connections. Then, right-click each connection tile, click Properties. Under usage, untick Enable background refresh. That should do the trick. At least, for me, that worked. :D
I've got a LibreOffice Calc spreadsheet that I use to keep track of my accounts receivable at work. Each sheet lists invoices and their status (paid, unpaid, etc) as well as info about each invoice. I'm trying to create a Summary sheet that lists certain data from each sheet. Creating the sheet manually is easy, but I'm trying to "automate" the process. I want the summary page to auto-update if I add a new sheet (or remove one) as I add and remove accounts to the file.
I know that LibreOffice assigns each sheet an index number that I could refer to in some sort of formula, but I cannot find a function that I can use to refer to that index number when getting a value from a cell within it. One would expect that a function like Sheet(2) would reference the second sheet, but, alas, that is not so!
I've tried using the indirect and address functions without success, but I'm not sure if I'm not understanding these functions or if they're not appropriate for what I'm trying to accomplish.
This has been a missing piece in Calc for a long time. The preferred solution is to write a user-defined function. Spreadsheet formulas do not access sheets by index number but Basic can.
The following function is from https://ask.libreoffice.org/en/question/16604/how-do-i-access-the-current-sheet-name-in-formula-to-use-in-indirect/.
Function SheetName(Optional nSheet)
If IsMissing(nSheet) Then
SheetName = ThisComponent.getCurrentController().getActiveSheet().getName()
Else
SheetName = ThisComponent.getSheets().getByIndex(nSheet-1).getName()
EndIf
End Function
Then get a relative address of the first sheet cell A1 like this.
=ADDRESS(1,1,4,,SHEETNAME(1))
A slightly different function is given at https://forum.openoffice.org/en/forum/viewtopic.php?f=9&t=49799.
I have spreadsheet and I'm basically going to use it for inventory tracking and management.
In one sheet I'll have an app on my phone fill a list when it reads
a QR code.
In the second sheet there is also a list with the
specific QR codes of each item.
I need to know when a cell in the first sheet has been updated and put that information in the following two cells.
I'm using this trigger to check if ANY cell in the document has been updated.
function cellEditTrigger()
{
ScriptApp.newTrigger('coolFunction').forSpreadsheet('awsomeSpreadsheetID').onEdit().create();
}
It works fine and it runs the 'coolFunction' function. However I can't seem to be able to get the time and date for the cells that have been edited and put that information in the next two cells.
I know I could use onEdit(e), but I still can't get the information from e.range and I would like my script to not have to be bound to the Spreadsheet.
Is there any way to accomplish this?
I've been working on an independent project for a client of mine. They wanted to produce a button that, upon the user-click, it would open up a user-form and have a variety of macro-related options to choose from: a drop-down list, checkbox, option select button, etc.
I created a test formula and submitted it to the client; they enjoyed it thoroughly and decided to sent me a file to 'copy & paste' my original code within their excel file.
Problem is; because I'm a tad bit inexperienced with VBA I've run into a problem where once I click the button - the user form doesn't show up.
Below is a Dropbox link of the original file I created and it's original code; as well as the file that I am trying to copy.
Any help would be all welcome and appreciated.
Link to dropbox: https://www.dropbox.com/sh/l1t37lz8uritrua/AAAdWPGvw0GDZ6hW4SwmbBdRa?dl=0
OriginalProject.xlsm has a form named honor_roll_form which contains 100 lines of code.
CopyOfOriginal.xlsm has a form named UserForm1 which contains no useful code.
I do not believe there is any method of directly copying user forms from one workbook to another. Instead
Within VB Editor of OriginalProject.xlsm, select honor_roll_form.
Click File then Export File and save the form on your desktop or where ever you like.
You will now have two files on your desktop; one with an extension of frm and one with an extension of frx.
Within VB Editor of CopyOfOriginal.xlsm, click File then Import file.
Import honor_roll_form.frm
When I try clicking button "Honor Roll", I get "Method or data member not found" for project1Box. I will investigate after dinner (18:57 here) unless you tell me you already know why I am getting this error.
Extra comments in response to request from OP
It is late here but I have started looking down sub execute_button_Click within the second CopyOfOriginal.xlsm. I will comment on what I see even if it is not directly relevant to the non-execution of the macro.
If you open the VB Editor and look on the left you will see the Project Explorer. Near the top you will see:
Microsoft Excel Objects
Sheet1 (Sheet1)
I have always found this confusing. The first “Sheet1” is Excel’s Id for the worksheet and cannot be changed. The second “Sheet1” is the default name for the worksheet which can be changed. You can write Sheet1.Range("A1") or Worksheets("Sheet1").Range("A1"). That is: you can reference a worksheet by its Id or its name. You have named a variable of type Worksheet as Sheet1. Using Excel’s names as variable names can lead to bizarre errors so it is important to avoid doing anything like this.
It is better to always use meaningful names. At the moment, you know what Sheet1 means but if you come back to this macro in six or twelve months will you remember. I would use a variable as you have but I would name it WshtCis208 or WshtVBAProg or something similar.
Set ID = Range(Sheet1.Cells(2, 1), Sheet1.Cells(52, 1)) could be written as:
With WshtCis208
Set ID = Range(.Cells(2, 1), .Cells(52, 1))
End With
Using With statements produces faster code and, almost always, code that it easier to read.
“52” is the current bottom row for this table. Will you amend the macro for them every time they add or remove a student? There are several techniques for finding the last row, none of which is perfect in every situation. The technique that is the most convenient most of the time is:
Const ColCis208Id as Long = 1
Const ColCis208MidTermExam as Long = 5
Dim RowCis208Last as Long
RowCis208Last = .Cells(.Rows.Count, ColCis208Id).End(xlUp).Row
At the moment, column 1 is the Id column. It is perhaps unlikely that the Id column will move but it is very likely that some of the others columns will move when some new column is identified as useful. Do you want to scan the code trying to decide which 5s refer to the MidtermExam column when a Project3 column is added?
Constants allow you to name literals that might change. It makes your code easier to read and saves so much pain when a value changes.
.Rows.Count gives the number of rows in a worksheet for the current version of Excel so .Cells(.Rows.Count, ColCis208Id) identifies the bottom cell of column 1. End(xlUp).Row says go up until you hit a cell with a value and returns its row number. It is the VBA equivalent of Ctrl+Up.
The next statement subjectCount = … fails because projectBox does not exist on the form. You have changed the captions but not the names.
As far as I can see the form fails to execute because you have started updating it but have not finished.