I have a workbook with 12 sheets that have raw data (IP address Subnets) on them. I have each of these sheets using a named range so I can reference the data later easily. There are actually several named ranges per sheet, I'm focusing on just one for the purpose of the question.
Then I have my Info sheet that has different tables listing information about all of the raw data sheets.
One of the tables is referring to each of the named ranges. Right now I have the named range typed in, but I'm going to be adding more raw data sheets and want to refer to the named ranges dynamically.
The way it is setup now:
The raw data sheets are named based on the IP Subnet information held on the sheet. The named range is named for the sheet.
For example: Sheet Name: "Data_10.1" = Named Range Name "NewIP_10.1": Data10.1!K1:K400
On my Info sheet I have a table that is telling me how many new IPs were found today, it looks like this:
IP Range
New IPs
10.1
=COUNTIF(NewIP_10.1,"Add") = 10
10.10
=COUNTIF(NewIP_10.10,"Add") = 3
I would like to change that formula to be dynamic so that it looks something like:
=COUNTIF(CONCAT("NewIP_",A2),"Add")
This however did not work.
Is there a way to call a named range dynamically?
Use INDIRECT:
=COUNTIF(INDIRECT("NewIP_" & A2),"Add")
Note that INDIRECT is volatile and recalculates every time Excel recalculates. It should be used sparingly or avoided if possible.
Related
The structure of my workbook is the following: there are UI sheets, calculation sheets, and a database sheet.
The user interacts with the UI sheets and macros are called from there.
Information is passed to the calculation sheet (via named range) and the calculation is executed there.
Outputs from the calculation sheet are passed to the UI sheet (via named range) and the database sheet (also via named range).
When the user "saves" a file, the program is only saving a copy of the database sheet to a new file. This is done so that the user does not overwrite the master file. When the user "opens" a file, that file is retrieved and the data passed from the saved file to the database sheet in the master file via named range.
To populate this database sheet, I pass values from the UI and calculation sheets by the following code:
ws_DB.range("rngName_UI").value2 = ws_UI.range("rngName_UI").value2
ws_DB.range("rngName_Calc").value2 = ws_Calc.range("rngName_Calc").value2
The only problem with this system is that my named ranges might gain new rows/columns over time if I need to output new information. That means that if I saved a database sheet with version 1 and some named range "rng_A" had 3 columns, but then I retrieve that in version 2 and "rng_A" has 5 columns, then Excel shows the last 2 columns with a #NA error.
Is there a convenient way to avoid this problem? My best idea so far is that I can get the rows and columns of the source and destination range(s) and then pass only to the minimum of the nRows and nCols. Is there a better solution?
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)
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()?
is there any way I can use Sheets INDEX instead of NAME to address it?
For example I have
Sheet1 (Calculations)
How can I address this sheet instead of using:
='Calculations'!CELL
I need it as sheets names will be changing according to their values
This link provides a way to do it with a user-defined function in VBA:
referencing sheets by number instead of name in cells
However, you may also want to consider a method that does not change the sheet names. As #DirkReichel implies, you can change sheet indices without changing sheet names and vice versa.
You might try using summary information stored on the sheet in question or keeping a summary sheet that references each sheet.
I am creating my own template which I need to use data from a worksheet called Schedules. The template contains 3 sheets, none of which are the Schedules sheet. This template will only be used in workbooks where the Schedules sheet already exists.
My question is, how do I reference a local worksheet which isn't in the template?
Whenever I create the template I reference the Schedules sheet but it asks for a file destination. How can I force it to look for a local sheet, even though the sheet won't exist until the template is actually used?
Depending on how complex your formulas, this could get messy pretty quickly, but one option would be to use the INDIRECT formula.
Some examples are below:
Gives you the value of A1 on the Schedules sheet
=INDIRECT("Schedules!"&"A1")
Looks up the ID '5' in the range A1:C20 in the Schedules sheet and returns the corresponding value in column B
=VLOOKUP(5,INDIRECT("Schedules!"&"A1:C20"),2,0)
Multiplies two values on the Schedules sheet
=INDIRECT("Schedules!"&"A1")*INDIRECT("Schedules!"&"A2")
Once you get your formulas working you can move your templates to the workbook that has the Schedules. All of your formulas will update with appropriate values, and for the record, calculations should be set to automatic.