I have an Excel sheet with powerpivot tables and charts. I want to show when the data was updated.
I use VBA code and a button to update the data, and I use the function now() in a cell which is updated when the code is running.
I have two problems.
When I open the Excel file the date is updated even if I do not update the data on start. (I do not want the data to update on start)
When the update fails the date is still updated.
My VBA code look like this:
Range("table name").Select
ActiveSheet.PivotTables("PivotTable2").PivotCache.refresh
Range("date cell").Select
How to avoid update when the data is not updated?
Instead of solve it as user3819867 suggested, I solved it by adding the information from the database, which is a SQL server database so I added a view with one colum and one row (with a getdate()) and send it along with the other tables so I get one extra table named "date".
How about its event?
Private Sub Worksheet_PivotTableUpdate(ByVal Target As PivotTable)
Range("date cell").Select
End Sub
Related
I have an excel which has sql queries associated with it. I open the excel , click on Data->Refresh All and send across to the users.
When I click on refresh All , I want the refreshed date to appear in a cell on that sheet. Can you give some hint on this.
Add another SQL Query somewhere else in your workbook
SELECT GETDATE()
Make sure you refer to the same database your original query is referring to.
when you refresh the spread sheet the date will be updated as well.
Select Data ribbon
From Other Sources
From Microsoft Query
Choose DataBase (same as one used for the original Query)
"Query Wizard - Choose Columns" Click Cancel
"Do you want to continue editing the data in Query" Click Yes
"Add Tables" Click Close
Click on "SQL Button" and add the query there "SELECT GETDATE()"
Click OK
Click on Return data to Microsoft Excel
Rather than using the Ribbon to perform the Refresh, try a little macro like:
Sub Macro1()
ActiveWorkbook.RefreshAll
With Range("A1")
.Value = Now()
.NumberFormat = "mm/dd/yyyy hh:mm:ss"
End With
End Sub
Pick whatever cell you like.
after searching various Excel related sites (mrexcel.com, exceltown.com and answers.microsoft.com) i've decided that the best solution (for me) does NOT need Macro or another query:
add as a last column in your existing query whatever function provides the current date and time [for Ingres it's date('now')]
hide the column from the resulting table
in the cell that you desire to show the last date & time that your table was refreshed enter the formula max(j:j). substitute j with the column that you've hidden.
simple :)
This was the easiest way for me to get a refresh date. Add a =Date.Time.LocalNow() column. Hide Column. https://exceloffthegrid.com/power-query-get-refresh-date-time/
I am currently working on a database for a small Company. They already have a first Version with several tables already implemented. What I would like to do is to create a master table in which data are going to be imported from Excel.
Everytime this table is updated, all the other tables should get updated aswell.
I am not sure how to implement this in Access, so this is whz I am asking for help.
Thanks in advance!
Maurizio
Following sub will import data from excel to access table. Table structure and excel data structure must be same (Column name, data type etc).
Private Sub cmdSpecificSheetOnly_Click()
Dim strExcelPath As String
strExcelPath = "C:\Users\HARUN\Documents\tblEmpInfo.xlsx"
'For Specific Range
'Call DoCmd.TransferSpreadsheet(acImport, acSpreadsheetTypeExcel5, "tblEmpInfo", strExcelPath, True, "Sheet1!A1:E31")
Call DoCmd.TransferSpreadsheet(acImport, acSpreadsheetTypeExcel5, "tblEmpInfo", strExcelPath, True, "Sheet1!")
End Sub
I have the following code in excel VBA
'Create query table to hold the rates.
With objBK.Worksheets(1)
Set objQT = .QueryTables.Add( _
Connection:="URL;https://xxx.output=XLS", _
Destination:=.Range("A1"))
End With
https://xxx.output=XLS return an XLS table that is written in A1 cell of my worksheet.
The problem is that every time I run this query it keeps adding the table in A1 shifting the previous table and NOT overriding it.
How can I override old table?
You keep adding new ones when you actually want to adjust the existing one. Give your QueryTable a name (objQT.Name = "blah"). Then when you need to adjust it, get hold of that QueryTable and make your adjustments to it.
Alternatively, just delete the old one before creating a new one.
I am pretty new to VBA in Excel. I have built a form which users enter data and at the press of a button it drops all that data into an excel spreadsheet and clears the form. What i need now is code for the user to push a button (off a list or combo box that shows already entered data) and have that data be brought back into the form for changes. I am trying to keep them out of the spreadsheet. Thanks
I think must be like this:
Private Sub Textbox1_Change()
Worksheets("worksheetname").Activate
TextBox1 = Cells(1,1).Text
End Sub
In "Cells()" you have to selecet the specific cell which contains the value. But if you want to use excel as a kind of a database you should think about if it's the right tool, maybe access would be better.
I have an Excel add-in (Bloomberg) which streams real-time prices into a spreadsheet. I need to add a column which contains the last time a price was updated. I've tried to do this with the worksheet change event, but this doesn't seem to get fired by the changes (I assume something to do with it being a real-time update).
The requirement is the same as the question below, but the solutions do not apply since the events do not fire in this case.
automatically execute an Excel macro on a cell change
With help from another forum, I've found an easy way to do this.
First define a function as below in a VBA module accessible to the sheet:
Public Function GetTime(target As Double) As Double
GetTime = Now()
End Function
Then in the 'last updated' column, add a call to this function with the formula pointing to the cell you wish to monitor. Whenever the target cell is updated, even from a real-time update, the function will fire and cause the time to be updated.