Bind a cell in one Excel sheet to a cell in another - vba

Say I had two Excel sheets (ONE.xlsx & TWO.xlsx). Would it be possible to have a certain cell in ONE to be changed at the same time as a certain cell in TWO?
For example:
B2 in ONE is equal to "Tuesday". Is there a way to make D10 in TWO also equal to "Tuesday" without having to go into TWO and manually changing it.
The more I think about this problem the more I think that it's not likley to work. The only way I can think of it working is by connecting them both up to the same database somehow. Thought I'd try you guys before I give up try something else.
Thanks in advance!

I've found a solution that works very well.
Open both the workbooks.
In the source workbook, copy the cell(s) that you wish to link.
In the destination workbook, right click and select "Paste Link".
The cells in the destination workbook should now be linked so that when changes are made to the source workbook the changes are also made in the destination workbook.

Sure, open both workbooks.
put = in workbook 2 minimize and find the sheet/cell in workbook one
select it.
close workbook 2 and save.
change the value in workbook 1
open workbook to (enable the security to look at workbook 1)
see the updated value.

Related

VBA - Pushing data from one workbook to another, irrespective of file names

Been in a pickle for a while (week or so) here and was hoping someone in this magical community could help me out. There is likely a very easy solution for an experienced individual, which I am not.
First, my goal is as follows: Push data from Workbook A to Workbook B via macro.
Conditions:
Workbook A must be able to be renamed without compromising the macro (it is a tool used in day-to-day functions and saved as a new name each use). Workbook A holds the macros.
Workbook B receives the data. Its name will also change with time, but in this case it needs to be based off written text in a cell from Workbook A (name change about yearly due to versioning) Let's just call it Cell A1 for argument's sake.
There may be additional workbooks open at the same time, related or unrelated.
To keep it simple, I will just post one line in my current macro, but I will be applying this to dozens. This works when I do not rename the files. I likely need help defining variables (strings?) and direction in what functions to use.
Windows("Workbook_B 4.7.5.xls").Activate
'*Workbook B name will ideally be derived from a cell value in Workbook A*
Range("V12") = "='[Workbook_A V1.2.5 .xlsm]SHEET_A '!R8C7"
In this chunk, the goal is to activate Workbook B and copy the value (or formula if it is easier), from cell G8 on Workbook A Sheet A to Workbook B(sheet is already active and sheet names will never change in either workbook).
Cheers!
"Workbook A holds the macros" - in this case you would use
ThisWorkbook
to refer to Workbook A
...and
Workbooks(ThisWorkbook.Sheets("Sheet1").Range("A1").Value)
to refer to Workbook B

Update master workbook with another workbook

There is lots of questions about copying the content of one workbook to another that I'm aware of.
I would like to make a code that updates the workbook by importing the content from the other workbook without rewriting cells, just adding values. I want to make it that way in case the other workbook is corrupted or have some data deleted.
Some rows can be partially filled but the macro will fit the correct information in the right row.
Have you considered trying to copy over the workbook as a different name?
Imagine you start with
MasterWB -> sheet1
ChildWB -> sheet1
You copy over such that you have this worksheets.
MasterWB -> sheet1 , sheet2(childbook)
From there it is pretty easy to do a concat on a third page. First create a third sheet. Next, concat the values on sheet3 with values from sheet2 and 1
MasterWB.sheet3.cellA1.value = concat(sheet2.cellA1.value, sheet1.cellA1.value)
Sorry for the bad syntax, hope this helps!

Is it possible to have a cell that has a formula and accepts entry at same time in excel?

Example:
A B
1 =vlookup(XX)
2
3
in cell A1 there is a Vlookup formula, Is it possible to enable user entry in this cell and override the formula then later restore the formula automatically when sheet is open again?
Even through VBA
Short, boring answer: nope.
A cell only ever has a keyed-in value, or a calculated formula. Can't have both.
Longer answer: maybe.
Shift everything 1 row down, and use row 1 to store your "original" formula - then hide that row (and pray the user isn't going to mess with it).
When the sheet is opened again sounds like you're confusing "workbook" and "worksheet" - you need to handle Workbook_Open if you want to run code when a workbook opens. Workbooks contain worksheets - it's the workbook that opens, not the sheets (sheets activate, but I doubt you would want to put that logic in there).
So, in the handler for Workbook_Open, write code that takes the formula in the hidden row and overwrites whatever is under it.
Another solution can be to hard-code the formula in the VBA code.
One possibility would be to store your Workbook as a template. Normally when a user opens the workbook by double-clicking, it will open whole new workbook based on the template, and they can modify it to their heart's content, save it, mail it to Grandma, etc.
The next person who comes along will double-click the template file and get the formula again, just as you designed it.
Short answer: Kind of, sort of
Long answer:
Save your workbook as a template. Every time someone will use it you'll see the orignal with formula, then if someone write over the formula, when using save your original will be kept intact.
What You need to do is:
press Alt + F11
select ThisWorkbook and paste this code:
Private Sub Workbook_Open()
Worksheets("Sheet1").Range("A11").Value = "asdf"
End Sub
Every time the workbook is opened, this script will run.
Instead of "Sheet1" you can write the name of the sheet you want to apply the script.
Inside the Range, You can define the cells you want to modify, You can use even multiple cells. Check this for more information about this.
After Value You can write what You want to be written inside the cell. You can write "=vlookup(XX)" and it will work.

Excel VBA - combining worksheets from multiple workbooks and rename new worksheet tab

I am trying to create some VBA code that will do the following:
Take worksheets 2 and 3 from a number of different workbooks (all in the same folder) and put them into a new workbook.
Worksheet 2 has the same name in each of the different workbooks so I want the VBA to also change the name of the new worksheet to a cell reference from the original worksheet (in this case cell A6)
Worksheet 3 has the same name in each of the different workbooks so I want the VBA to also change the name of this new worksheet to the same cell reference (A6), combined with the text "ph"
Any help would be gratefully received
Rob
You'll be able to figure out all of the code you need with the help of the Macro Recorder. Turn that on and manually do your listed steps (make sure you stop recording when that's done), then look for pieces of code that move the worksheets and rename them. Once you see that code, you can figure out how to customize it to your needs.

Copy and paste between workbooks

This is a question and may or may not be achievable but any recommendation is much appreciated.
Is it possible to have one workbook (wrkbookA) open that has all the data and vba code in it. Click button to open/navigate to a directory and select another workbook (wrkbookB). wrkbookB is opened, select a column, that column is copied and pasted into wrkbookA in column A and wrkbookB is closed.
I know this can be achieved using a constant column from wrkbookB but the data is in differnet columns in each workbook in wrkbookB.
I have also looked at column headings and doing the copy that way but it is not an option as there are different columns with similar heading/words.
Thanks everyone.
Since you don't have any way of knowing which Column will need to be selected from workbook B, you're going to need user interaction. that being the case, why not write a sub that will do the following:
Have user select workbook B to open
Place a button in Workbook B attached to code in Workbook A
User then, in Workbook B, selects the column they want copied and push the button which copies that column to Workbook A and closes Workbook B without saving changes.
Sample Code Idea:
Workbooks.Open ...
ActiveSheet.Buttons.Add(427.5, 12.75, 104.25, 36).OnAction = "WorkBookA!MoveColumn"