Reference active sheet in another workbook - excel

I have a workbook (logging.xlsx) with one sheet per month. In this sheet I enter different numbers per month.
To visualize the information from the logging workbook, I want to use some charts in an external (reporting) workbook. I prefer to have these charts in an external workbook, as the format of the logging workbook is not totally under my control.
To grep information from the logging workbook I'd like to automatically sync the information into the reporting workbook. To do so I can use external references like =[logging.xlsx]July!$I$1, however, this requires to make one reporting sheet per sheet in the logging workbook which increases the maintenance work in the reporting workbook.
Hence I was wondering whether there is a way, instead of =[logging.xlsx]July!$I$1 to use something like =[logging.xlsx]*ACTIVE_SHEET*!$I$1

In D10 add the formula:
=CONCATENATE("[";$A$1;"]";$B$1;"!";ADDRESS(ROW(),COLUMN()))
In the second sheet use:
=INDIRECT(ref!D10)

Related

Identify the name of the sheet, then extract the data from said sheet

I'm trying to find a way to create a macros that would read the name of the sheet from an external workbook, and extract the necessary information from that sheet, but when I run it again, it would take from the next sheet? To make it clear:
A set of daily volumes are placed into an excel workbook where each sheet in the workbook is represented by the date (i.e. 31 sheets in a workbook for the month of May).
How can I make the Macros take the volume for May 6th volumes, but for the next day when I run the Macros it would take from May 7th etc?
Hope I made it clear and apologies for any inconvenience.

How can I use Excel VBA to update links only in a specific worksheet and not the whole workbook?

I have an Excel file where some data from multiple geographies come together. People from one geography don't have access to the sharepoint of other geographies. Each geography has its own worksheet where the data should be updated once a month.
I would like to have a button on each worksheet where once a month someone from each geography updates their worksheet before it is bundled together into one worksheet.
The function .UpdateLinks only works with the whole workbook which is not desirable since the sharepoint access is divided.
I tried to set Excel calculation to manual and afterwards made a button to .Calculate that specific sheet but it seemed to work at first but is not reliable.
ThisWorkbook.Sheets("worksheet1").Calculate '(inconsistent)
ThisWorkbook.Sheets("worksheet1").UpdateLink '(doesn't work)
I would like to have a button to update links only in a specific worksheet and not the whole workbook.
The Workbook.UpdateLink method is located in Workbook and does not exist in Worksheet therefore it is only possible to update the links of the whole workbook but not of single worksheets only.
Updating links in single worksheets only is not supported.

I need to dynamically reference from one excel workbook to another

I have an excel workbook titled "Invoices" that contains invoicing templates for approximately 35 employees. Cosmetically, all of the sheets are the same, except for employer, pay rate, name etc. Each employee has a different sheet within this workbook.
In addition, I get weekly "Master Time card reports" for approximately 120 employees that I must download as a separate excel workbook weekly. Each one of these employees has a separate worksheet. The data from the "Master Time card reports" must be transferred to the templates on the "Invoices" workbook. I have been doing this manually, and have been trying to figure out a way in Excel to dynamically reference the sheets in the "Master Time card reports" workbook from the "Invoices" workbook.
The issue is that the cell addresses on the "Master time card reports" change, depending on a number of factors. One week, the total hours for any particular employee may be in cell "T50", and then the next week they may be in cell "T43" (they never change columns). Also, the names of the sheets may change from "Sheet1" to "Sheet3", because new employees are added, or roll off.
I have done an extensive amount of research and can't seem to find a way to do this.
This is the formula that I am using so far:
=INDIRECT("'[Mastetimecardreports.xlsx]*'!B"&MATCH($D18,[Mastetimecardreports.xlsx]Sheet1:Sheet129!$B:$B,0)+1)
My goal is to enter the name of an employee on their respective worksheet in the "Invoices" workbook and have that name be found in the "Master time card reports" workbook and pull data from the sheet for that respective employee. I want to do this dynamically, as the cell address and sheets will always be changing.
You may greatly benefit from a data architecture restructure. Whenever I read something like Each employee has a different sheet within this workbook, my alarm bells go off. Why would you do that? Why would you spread your data around multiple workbooks and inside those workbooks into multiple worksheets? This is the reason for your difficulty to aggregate the data. Use ONE workbook and ONE worksheet to store the data. If your data collection is in different files, Power Query can be used to create the ONE data file. Then you can easily create reports off that one data file.

Change worksheets number automatically in vba code

I have a VBA enabled excel workbook which has more than 20 sheets. Now the code in the VBA is using Worksheets numbers to call the worksheets.
Now I will have to delete one sheet which makes all the code unusable because if I delete one sheet the worksheet number changes.
Example Worksheets(10).Activate will point to another worksheet since I will be deleting the third worksheet
I am fairly new to this, so what would be the fastest way instead of manually changing the worksheet number in the code.
Note that there are 3 ways to access a sheet …
by its position in the tab bar:
Worksheets(10) gives the 10ᵗʰ worksheet in the tab bar.
Note that if you also have eg chart sheets the numbering is different from Sheets(10) which then might be a completely different sheet.
by its visible tab bar name:
Worksheets("Sheet10")
by its VBA name:
Sheet10
Note that the VBA name can only be changed in the Project window of the VBA-Editor.
Note that Worksheets(10), Worksheets("Sheet10") and Sheet10 can be completely different sheets, because they use 3 completey independ naming systems.
Which one to use highly depends on what you are actually trying to do. There is no best option in general each of them has their advantages and disadvantages.
Additionally I highly recommend not to use .Activate and .Select at all. Therefore read How to avoid using Select in Excel VBA.

Updating a workbook's existing structured table from an external master table?

Currently: I have a few sheets that contain one or more tables (e.g., Sheet1 has one table while Sheet2 has three tables). These same sheets are found in several end user workbooks. The tables in those sheets are used by structured references within cell formulas in the workbook.
Goal: I would like to have another workbook (a master workbook) that only has the sheets that contain the tables. Updates would be manually made to the master workbook i.e., add a row, delete a row, edit a row, add a column, delete a column, edit a column. Once updates are completed with the master workbook, the updated [master] sheets would then be placed into the various user workbooks, replacing the existing sheets and thus the tables (using VBA)...without breaking the structured references! No #REF errors! Well, this is what I'm envisioning, however, it doesn't have to be exactly this. Also, the common table sheets must be in the end user workbook, no external referencing! Unless it's part of the process to make what I need work, of course :-)
I'm very handy with VBA but not a MVP. Assume all of the workbooks -- both end user and master -- exist in the same directory. The master workbook would contain the code that would deliver the updated sheets to the end user workbooks. Excel 2007 & 2010 in Windows 7 environment.
I don't have any code as I'm trying to manually figure it out first without breaking anything. Suggestions welcomed! Thank you.
[Update 13Jun2012] Hopefully this more long-winded explaination will help.
What I'm doing:
I have a workbook that (essentially) copies itself into an end user workbook (1 to n times based on user form inputs). The end user workbook is protected to keep end users from making mistakes in certain formulas (various forms of sheet/cell protection). There are some sheets that contain tables and these tables are the same for all users. These tables are used for data validation (e.g., Allow: List; Source: =timing_droplist) and VLOOKUPs (e.g., =VLOOKUP($W8,Timing_table,FE$5+1,FALSE)). These end user workbooks are created once a year but updated three times during the year (they're for finance/budgeting). The tables can be updated at any time. Since data is added to the end user workbooks it's not convienent to re-generate those workbooks with the updated tables and then have the end user re-enter all their data. So it would better if the existing end user workbooks could have the common tables updated all together (using VBA).
What's happening (just ONE example):
"Timing" sheet exists and contains the table "Timing_table". If the master "Timing" sheet is added to the workbook, Excel renames it to "Timing (2)". This is normal. But the table in the added sheet becomes local instead of globle AND it, too, gets renamed, FOR EXAMPLE, "Timing_table12". I don't know how Excel comes up with the digits for the table name and they could change. If I delete the old "Timing" sheet all references to it are broken (of course) -- pulling up Name Manager shows #REF! in the value column. Renaming the new references doesn't fix the issue because the new references are local to the new sheet.
I tried manually cutting and pasting a table into another, pasting as Text, and that doesn't keep formulas (basically it performs a Paste as Values operation) and, overall, doesn't work. Just looking for options. External references to these tables is not an option.
I think that this thread might help you out: http://www.ozgrid.com/forum/showthread.php?t=66791
To provide you the reply directly (assuming that the problem mainly involves the external referencing):
Replied by Aaron Blood:
Re: Copy Formula To New Worksheet Without Path
You've already developed the code to do the copy/pasting to a new sheet and workbook. Now all you need to do is scan the formulas of the new worksheet and remove the ext refs from the formulas.
Run something like this at the end of your existing copy/paste macro...
VB:
Sub ExtRef_Remover()
Dim cell As Range, n As Variant
For Each cell In Workbooks("New_WB").Sheets("Sheet1").Cells.SpecialCells(xlFormulas)
n = Application.Find("]", cell.Formula)
If Not IsError(n) Then
cell.Formula = "='" & Right(cell.Formula, Len(cell.Formula) - n)
End If
Next cell
End Sub
Using extensive external references just didn't work out in this project so I convinced the project manager that we needed to change course. She agreed that what she wanted was too much to ask and taking too much time to implement, aside from compromising workbook generation and stability. I ended up using a data pull into the necessary tables via a command button. Waaaay easier to work with and stable.

Resources