I am not sure if this is too ambitious. Currently I'm generating a bunch of pivot tables through our server (I won't go into detail) but our main stocktaking spreadsheet references these generated pivot tables weekly and pulls their figures through.
i.e using code ='C:\Users\ITS1\Documents\Test\Establishment\190303[Stocktake.xlsx]Data4'!$D$3 which is simple enough - just referencing whatever figure is in that cell on the pivot table.
There is a particular bunch of figures on some pivot tables each week called 'Redemption' which, depending on what other kind of sales an establishment generates, shift to different cells each week. So I can't reference them like other figures which are always fixed to the same cells on every generated pivot table.
Is there a way I can reference the pivot table by the keyword 'Redemption' and take the figure from the cell directly next to it which is the actual figure we need to record?
While this isn't hugely urgent, it would be quite handy. These figures can just be manually entered but just trying out some automation to eliminate my human error :)
If you don't want to have to open the external workbook, this approach might be feasible:
In the external workbook, create a helper sheet that uses a formula to look up the Redemption field value. This could possibly be done with a GetPivotData formula. The exact formula depends on your data and without seeing that I can't write it.
The idea here is that the helper sheet and the location of the cell on the helper sheet does not change. When the pivot table is refreshed, the formula calculates the result.
In the other workbook you can now use an absolute reference to that helper sheet and cell and don't need to open the external file to retrieve the value.
Related
I have table-like data, and I'm looking to make a chart that displays that data. Since the data is that formula-generated from other data in the workbook, I don't know in advance how many lines it will have. I want to make a chart that adapts to this data.
Up to this part of the question, I could use named ranges to solve this.
The thing with the solution with named ranges is that it does not scale well when I have many of these charts. I have a Python script that generates CSV files that I import into my workbook as a sheet, and I don't want to have to know in advance how many of them there will be, or what they will be named. I only want to be able to import the CSV files into a new or existing sheet, and copy-paste the formulas from another working sheet, as well as be able to replace the existing CSV data with new data.
With named ranges, I would have to manually create a named range for each series of each sheet, and I would have to use the sheet's name so that the named range can be visible to the whole workbook (in order to analyze the data in a global sheet) without any name conflict. This is (more or less) acceptable when I do these steps myself now, but if I want to redo this in a few months, or if I pass my workbook to someone else, we wouldn't know why it's not working with a new sheet.
So is there any way to get this done without delving into VBA stuff? I'm using a recent version of Excel.
Per the comments, try using pivot tables, making your range extend far beyond expected results and filtering out "blanks" in your pivot and generate your chart from that. The default pivot chart is ugly but you can remove buttons and format as needed. Just remember to refresh your pivot during every update period.
I have one excel file in which I have multiple sheets with financial statements from different companies (called Databas.xlsx). The structures of these sheets are identical. Then I have another excel file that I wish to use to analyse these financial statements using charts. Thus, I must get data from the different sheets into my analysis file. Doing this from one sheet is no problem, as I can simply create a chart and mark the data I need from this sheet, so that the chart data range would be something like this:
=[Databas.xlsx]Kopparbergs!$C$3:$K$3
where "Kopparbergs" is the sheet name in Databas.xlsx. The problem I am facing is that I want to be able to change the sheet name that is put into this formula by writing the name in a cell (because that would enable me to change multiple charts at once). So just to clarify, in the formula written above, I want to be able to change the word "Kopparbergs" by writing text in a cell. If that is not possible, how would I accomplish this? That is, how do you create a chart that can change its content depending on a text in a cell that corresponds to a sheet?
So rather than using Indirect I think you need to use two named ranges for referencing when using a Chart.
This previous answer looks like a good guide to implement (not sure about etiquette of just copy & pasting previous answers so I'll just provide the link):
Dynamic chart range using INDIRECT: That function is not valid (despite range highlighted)
I'm resurrecting some old scientific data from the early 2000s.
I need to locate the custom functions that allowed the data to be shown. The spreadsheet that I have is full of #REF! cells, as they are supposed to be calculated based on a custom-defined formula (here, called 'RESECTION').
How do I find this formula? If I can see the math it was performing, I will be able to use this old data, and extend our timeseries significantly.
The spreadsheet is an ".xlsm" document. There is an associated file that is ".XLM"; it provides some GUI-like functionality that is now broken, and I do not see how to access the commands (?) or other VBA that is inside.
I have not had success with this solution.
File with the VBA can be found here; SURVEY.XLM.
Problem is seen here; calling function from SURVEY.XLM. How do I access the formula within here?
I can see that the formula is in there; how do I see the calculation it performs?
RESECTION is a named range refering to cell A4 on the hidden Survey sheet.
In the VBE immediate window type thisworkbook.Sheets(2).visible = true and then thisworkbook.Sheets(2).select.
Cell Survey!A4 contains the value =RESULT(64).
The rest of the sheet contains the macros - first time I've seen or tried to use a filled in macro sheet.
I tried Ctrl+Fto find the definition of RESULT but it comes up with Macro error at cell [SURVEY.XLM]SURVEY!A364.
In my database, I have created separate worksheets for different sources of data, to make the database more structured for the users. In the summary page I created, I would like to dynamically refer to these worksheets, to easily visualize the data.
The "sheet selection" looks as follows.
Site should determine from which sheet the data comes. Afdeling and Data are columns in these sheets, and its values are used to find the data range (row start and row stop).
In this excellent question and answer, it is explained how to dynamically refer to a specific data range by Function, without the use of Indirect() (Why I don't want indirect). However, it does not answer how to refer to a sheet.
Is it possible to select the worksheet in an excel file by function, without using Indirect()?
I'm trying to find a way to from a Cell get the data from a cell in the Sheet that lies to the Left (down in the tray) of the current Sheet.
I know how to call to other sheets via
=Sheet1!A1
But now I need something best explained with
=Sheet[-1]!A1
Any ideas?
Using the tab order as a fundamental part of your calculations is a complicated and risky approach to Excel calculations. Excel offers many alternatives which you'd be better off using:
A simplified version of belisarius's suggestion is: =INDIRECT(A1 & "!A2") where cell A1 has the name of your datasource sheet and A2 has the name of your target cell in your datasource sheet. If you know the name of your sheet of interest (or can look it up in some way), use this method.
If you need to do this often, you might want to export the data into an actual database (i.e. MS Access). Then you can make standard SQL queries and import the results into your Excel file.
If you absolutely want to go the VBA route, then you'd have to write some code that:
3a. Grabs all the names of the active workbook and stores them in an array.
3b. Identifies the index number of the currently active workbook in that array. Subtract 1 from that index to get the sheet to the left.
3c. Gets the cell value from that sheet.
You can also get freaky with Named Ranges. In Excel 2003, go to Insert->Name->Define, add a new Named Range and you can use that name in your calculations instead of referring to the cell by row and column.
Edit
The whole Idea with this one, is that
you have the Sheets arranged, and are
able to move them around, and that
shall change the calculations. – Gnutt
1 hour ago
Please, please, don't do that. For starters, this isn't a standard method of interaction with a spreadsheet. Your end-users will likely be confused and may not even ask for clarification.
You'll want to explore the idea of data validation:
Using Data->Validation, make a drop-down menu listing all the sheets in the workbook (if the names of all the sheets are static, you can just hardcode them, otherwise, you'll need some VBA to pull them).
Then the user just picks the sheet of their choice and indirect() will automatically update everything.
Alternatively, you can also check out Tools->Scenarios. I don't know anybody who uses this feature, but you might be a good candidate for it. Basically, it lets you see the results of calculations using different datasets (i.e. "scenarios") so the user can go back and forth between them.
Using either of the 2 methods above, there's a good chance you can avoid VBA entirely, thus saving users that annoying warning message when they open your file.
=INDIRECT("Sheet"&TEXT(VALUE(MID(CELL("filename",A8),FIND("]",CELL("filename",A8))+1,256))-1,"#")&"!A1")
Caveats:
Your workbook must be saved previously
A8 may be replaced by a reference to ANY non-error cell
I know it's not seen here as good practice, but I want to do something similar. And it does replicate database functionality to an extent but I don't have the time or support to build one from scratch when there's something already half in place.
The reason I want to be able to do this is to create a summary table that links to all the worksheets in the workbook, and automatically extends if you insert a new worksheet. This is to manage a large sales / reporting spreadsheet with lots of different business units that all have the same structure (ie use the same worksheet format to report the same outcomes for different people. There is a high turnover. I want to have several summary sheets reporting different aspects of the source sheets. This is very time consuming to manage if recreating all of the tables each time.
You should be able to use the row() as an index marker to define the information that you want using something like REPLACE, OFFSET or INDEX but you can't as they only refer to 2D arrays.
Whereas Excel treats 3-D references as arrays for statistical functions it does not seem to do the same for reference functions. You might have SUM(sheetX:sheetY!A1) and be able to add a sheet in between, there is not (eg) a INDEX(sheetX:sheetY!A1,n) function. I've tried experimenting using these 2D functions as part of array formulas, and defining the 3D reference as an array or a named range... well it was worth a go :).
So I believe it's a valid action. I also believe there must be a way to do it, but for now I'm falling back on a UDF that has the risk of errors caused by calculation issues, or manipulating a Workbook_SheetChange function or similar. Or creating a single master sheet to control all the others which is populated by using a subroutine based on an array of all workbooks.
these functions work well for me. They get the worksheet index (the parent of
the range you call them with), add or subtract from that index, and then create
a range from that (relative) sheet and the address passed in.
Function relativeSheet(r As Range, iRelative As Integer)
Application.Volatile
relativeSheet = Sheets(r.Cells(1, 1).Parent.Index + iRelative).Range(r.Address)
End Function
Function prevSheet(r As Range)
prevSheet = relativeSheet(r, -1)
End Function
Function nextSheet(r As Range)
nextSheet = relativeSheet(r, 1)
End Function